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 /lib/arel/algebra | |
parent | 5b3433069fc94e120555ae4d218f6be19d2e51d4 (diff) | |
download | rails-56f2de870a7279e11575f6d0c6f2f9eea1374407.tar.gz rails-56f2de870a7279e11575f6d0c6f2f9eea1374407.tar.bz2 rails-56f2de870a7279e11575f6d0c6f2f9eea1374407.zip |
take advantage of inheritence for easier codes
Diffstat (limited to 'lib/arel/algebra')
-rw-r--r-- | lib/arel/algebra/relations/writes.rb | 30 |
1 files changed, 16 insertions, 14 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) |