diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-20 17:30:54 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-20 17:30:54 -0700 |
commit | 56f2de870a7279e11575f6d0c6f2f9eea1374407 (patch) | |
tree | 5a7b3f9ff0854bf51d0e416144b1c9bb9e172b2a | |
parent | 5b3433069fc94e120555ae4d218f6be19d2e51d4 (diff) | |
download | rails-56f2de870a7279e11575f6d0c6f2f9eea1374407.tar.gz rails-56f2de870a7279e11575f6d0c6f2f9eea1374407.tar.bz2 rails-56f2de870a7279e11575f6d0c6f2f9eea1374407.zip |
take advantage of inheritence for easier codes
-rw-r--r-- | lib/arel/algebra/relations/writes.rb | 30 | ||||
-rw-r--r-- | lib/arel/engines/memory/relations/writes.rb | 2 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations/writes.rb | 6 |
3 files changed, 20 insertions, 18 deletions
diff --git a/lib/arel/algebra/relations/writes.rb b/lib/arel/algebra/relations/writes.rb index d344987915..17da2b172b 100644 --- a/lib/arel/algebra/relations/writes.rb +++ b/lib/arel/algebra/relations/writes.rb @@ -1,33 +1,35 @@ module Arel - class Deletion < Compound - attributes :relation - deriving :initialize, :== + class Action < Compound + def == other + super || self.class === other && @relation == other.relation + end + end + class Deletion < Action def call engine.delete(self) end end - class Insert < Compound - attributes :relation, :record - deriving :== + class Insert < Action + attr_reader :record def initialize(relation, record) - @relation, @record = relation, record.bind(relation) + super(relation) + @record = record.bind(relation) end def call engine.create(self) end - end - class Update < Compound - attributes :relation, :assignments - deriving :== - - def initialize(relation, assignments) - @relation, @assignments = relation, assignments.bind(relation) + def == other + super && @record == other.record end + end + + class Update < Insert + alias :assignments :record def call engine.update(self) diff --git a/lib/arel/engines/memory/relations/writes.rb b/lib/arel/engines/memory/relations/writes.rb index 12c4f36c0d..39c1170ddc 100644 --- a/lib/arel/engines/memory/relations/writes.rb +++ b/lib/arel/engines/memory/relations/writes.rb @@ -1,5 +1,5 @@ module Arel - class Insert < Compound + class Insert < Action def eval unoperated_rows + [Row.new(self, record.values.collect(&:value))] end diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb index 4ed817f85d..50a2ce2e99 100644 --- a/lib/arel/engines/sql/relations/writes.rb +++ b/lib/arel/engines/sql/relations/writes.rb @@ -1,17 +1,17 @@ module Arel - class Deletion < Compound + class Deletion < Action def to_sql compiler.delete_sql end end - class Insert < Compound + class Insert < Action def to_sql(include_returning = true) compiler.insert_sql(include_returning) end end - class Update < Compound + class Update < Insert def to_sql compiler.update_sql end |