diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-02 21:10:35 -0800 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-02 21:10:35 -0800 |
commit | 6647a1e08eb9dc3512628882bcf60d421df74228 (patch) | |
tree | 204eebc8e9c6e6711331706dbd14815164db2eda /lib/active_relation/extensions | |
parent | c54392872f024d55e8a23ead3065e6119a52b234 (diff) | |
download | rails-6647a1e08eb9dc3512628882bcf60d421df74228.tar.gz rails-6647a1e08eb9dc3512628882bcf60d421df74228.tar.bz2 rails-6647a1e08eb9dc3512628882bcf60d421df74228.zip |
scalars are now lifted; the heavy lifting is done by the operations on relation (select, join, etc.)
Diffstat (limited to 'lib/active_relation/extensions')
-rw-r--r-- | lib/active_relation/extensions/array.rb | 4 | ||||
-rw-r--r-- | lib/active_relation/extensions/class.rb | 7 | ||||
-rw-r--r-- | lib/active_relation/extensions/hash.rb | 12 | ||||
-rw-r--r-- | lib/active_relation/extensions/object.rb | 16 |
4 files changed, 12 insertions, 27 deletions
diff --git a/lib/active_relation/extensions/array.rb b/lib/active_relation/extensions/array.rb index 5b6d6d6abd..aa4354a78a 100644 --- a/lib/active_relation/extensions/array.rb +++ b/lib/active_relation/extensions/array.rb @@ -2,4 +2,8 @@ class Array def to_hash Hash[*flatten] end + + def to_sql(strategy = nil) + "(#{collect(&:to_sql).join(', ')})" + end end
\ No newline at end of file diff --git a/lib/active_relation/extensions/class.rb b/lib/active_relation/extensions/class.rb deleted file mode 100644 index 72b3bf0c15..0000000000 --- a/lib/active_relation/extensions/class.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Class - def memoize(method) - define_method "#{method}_with_memoization" do |*args| - end - alias_method_chain method, :memoization - end -end
\ No newline at end of file diff --git a/lib/active_relation/extensions/hash.rb b/lib/active_relation/extensions/hash.rb index 50864912bf..a33ace5738 100644 --- a/lib/active_relation/extensions/hash.rb +++ b/lib/active_relation/extensions/hash.rb @@ -1,11 +1,11 @@ class Hash - def alias(&block) - inject({}) do |aliased, (key, value)| - aliased.merge(yield(key) => value) - end + def bind(relation) + descend { |x| x.bind(relation) } end - def to_sql(strategy = nil) - "(#{values.collect(&:to_sql).join(', ')})" + def descend(&block) + inject({}) do |descendent, (key, value)| + descendent.merge(yield(key) => yield(value)) + end end end
\ No newline at end of file diff --git a/lib/active_relation/extensions/object.rb b/lib/active_relation/extensions/object.rb index b0c7ada999..d13cf9aabb 100644 --- a/lib/active_relation/extensions/object.rb +++ b/lib/active_relation/extensions/object.rb @@ -1,18 +1,6 @@ -class Object - def qualify - self - end - +class Object def bind(relation) - self - end - - def to_sql(strategy = self.strategy) - strategy.scalar self - end - - def strategy - ActiveRelation::Sql::Scalar.new(ActiveRelation::Table.engine) + ActiveRelation::Scalar.new(self, relation) end def metaclass |