diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-25 18:37:00 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-25 18:37:00 -0700 |
commit | ef231deb9ef032e0910dcaec240b70996fc5e44e (patch) | |
tree | 6c8d1c2fad8789a93675011874e19076b8325acc /lib | |
parent | 181f4633b8aff0efdff6643ddee800d6f78d1eac (diff) | |
download | rails-ef231deb9ef032e0910dcaec240b70996fc5e44e.tar.gz rails-ef231deb9ef032e0910dcaec240b70996fc5e44e.tar.bz2 rails-ef231deb9ef032e0910dcaec240b70996fc5e44e.zip |
speed up method lookup by not mixing in modules
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/engines/memory/engine.rb | 12 | ||||
-rw-r--r-- | lib/arel/engines/sql/engine.rb | 40 |
2 files changed, 21 insertions, 31 deletions
diff --git a/lib/arel/engines/memory/engine.rb b/lib/arel/engines/memory/engine.rb index c7ac9422d4..0142c49aa3 100644 --- a/lib/arel/engines/memory/engine.rb +++ b/lib/arel/engines/memory/engine.rb @@ -1,16 +1,10 @@ module Arel module Memory class Engine - module CRUD - def read(relation) - relation.eval - end - - def create(relation) - relation.eval - end + def read(relation) + relation.eval end - include CRUD + alias :create :read end end end diff --git a/lib/arel/engines/sql/engine.rb b/lib/arel/engines/sql/engine.rb index a314a972c0..8504fec3c5 100644 --- a/lib/arel/engines/sql/engine.rb +++ b/lib/arel/engines/sql/engine.rb @@ -1,7 +1,6 @@ module Arel module Sql class Engine - def initialize(ar = nil) @ar = ar end @@ -28,32 +27,29 @@ module Arel end end - module CRUD - def create(relation) - primary_key_value = if relation.primary_key.blank? - nil - elsif relation.record.is_a?(Hash) - attribute = relation.record.detect { |attr, _| attr.name.to_s == relation.primary_key.to_s } - attribute && attribute.last.value - end - - connection.insert(relation.to_sql(false), nil, relation.primary_key, primary_key_value) + def create(relation) + primary_key_value = if relation.primary_key.blank? + nil + elsif relation.record.is_a?(Hash) + attribute = relation.record.detect { |attr, _| attr.name.to_s == relation.primary_key.to_s } + attribute && attribute.last.value end - def read(relation) - rows = connection.select_rows(relation.to_sql) - Array.new(rows, relation.attributes) - end + connection.insert(relation.to_sql(false), nil, relation.primary_key, primary_key_value) + end - def update(relation) - connection.update(relation.to_sql) - end + def read(relation) + rows = connection.select_rows(relation.to_sql) + Array.new(rows, relation.attributes) + end - def delete(relation) - connection.delete(relation.to_sql) - end + def update(relation) + connection.update(relation.to_sql) + end + + def delete(relation) + connection.delete(relation.to_sql) end - include CRUD end end end |