diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-11 23:22:26 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-11 23:22:26 -0700 |
commit | 12ef6a5ad15078d2f634d3c6cdfc453848f90122 (patch) | |
tree | 426f7fee7383bda64c050bc125733ba48e592d18 /lib/active_relation | |
parent | a29ceffc9476c99ff02f0617d2e38627c526bac2 (diff) | |
download | rails-12ef6a5ad15078d2f634d3c6cdfc453848f90122.tar.gz rails-12ef6a5ad15078d2f634d3c6cdfc453848f90122.tar.bz2 rails-12ef6a5ad15078d2f634d3c6cdfc453848f90122.zip |
refactored session's interaction with engine/connection
- follows law of demeter
- Table.engine uses AR::Base adapter
Diffstat (limited to 'lib/active_relation')
-rw-r--r-- | lib/active_relation/relations/deletion.rb | 4 | ||||
-rw-r--r-- | lib/active_relation/relations/insertion.rb | 4 | ||||
-rw-r--r-- | lib/active_relation/relations/relation.rb | 4 | ||||
-rw-r--r-- | lib/active_relation/relations/update.rb | 4 | ||||
-rw-r--r-- | lib/active_relation/sessions/session.rb | 8 |
5 files changed, 20 insertions, 4 deletions
diff --git a/lib/active_relation/relations/deletion.rb b/lib/active_relation/relations/deletion.rb index f3d81baf27..c5906e8bc8 100644 --- a/lib/active_relation/relations/deletion.rb +++ b/lib/active_relation/relations/deletion.rb @@ -12,6 +12,10 @@ module ActiveRelation ].compact.join("\n") end + def call(connection = engine.connection) + connection.delete(to_sql) + end + def ==(other) self.class == other.class and relation == other.relation diff --git a/lib/active_relation/relations/insertion.rb b/lib/active_relation/relations/insertion.rb index 16fe3d5f46..036db1a319 100644 --- a/lib/active_relation/relations/insertion.rb +++ b/lib/active_relation/relations/insertion.rb @@ -15,6 +15,10 @@ module ActiveRelation ].join("\n") end + def call(connection = engine.connection) + connection.insert(to_sql) + end + def ==(other) self.class == other.class and relation == other.relation and diff --git a/lib/active_relation/relations/relation.rb b/lib/active_relation/relations/relation.rb index f9823bf92d..69935a7be0 100644 --- a/lib/active_relation/relations/relation.rb +++ b/lib/active_relation/relations/relation.rb @@ -115,6 +115,10 @@ module ActiveRelation ].compact.join("\n"), self.alias end alias_method :to_s, :to_sql + + def call(connection = engine.connection) + connection.select_all(to_sql) + end def attribute_for_name(name) attributes.detect { |a| a.alias_or_name.to_s == name.to_s } diff --git a/lib/active_relation/relations/update.rb b/lib/active_relation/relations/update.rb index c50919af3e..0914cda035 100644 --- a/lib/active_relation/relations/update.rb +++ b/lib/active_relation/relations/update.rb @@ -16,6 +16,10 @@ module ActiveRelation ].join("\n") end + def call(connection = engine.connection) + connection.update(to_sql) + end + def ==(other) self.class == other.class and relation == other.relation and diff --git a/lib/active_relation/sessions/session.rb b/lib/active_relation/sessions/session.rb index 4bdbe69978..fe917a0e4d 100644 --- a/lib/active_relation/sessions/session.rb +++ b/lib/active_relation/sessions/session.rb @@ -25,22 +25,22 @@ module ActiveRelation module CRUD def create(insert) - insert.engine.insert(insert.to_sql) + insert.call(insert.engine.connection) end def read(select) @read ||= Hash.new do |hash, select| - hash[select] = select.engine.select_all(select.to_sql) + hash[select] = select.call(select.engine.connection) end @read[select] end def update(update) - update.engine.update(update.to_sql) + update.call(update.engine.connection) end def delete(delete) - delete.engine.delete(delete.to_sql) + delete.call(delete.engine.connection) end end include CRUD |