Class: Fauxsql::ManymanyWrapper
- Inherits:
-
AttributeWrapper
- Object
- AttributeWrapper
- Fauxsql::ManymanyWrapper
- Defined in:
- lib/fauxsql/manymany_wrapper.rb
Defined Under Namespace
Classes: InvalidManymanyAssociationClass, ThroughOptionMissing
Instance Attribute Summary
Attributes inherited from AttributeWrapper
#attribute, #name, #options, #record
Instance Method Summary collapse
- #<<(other) ⇒ Object
- #delete(*others) ⇒ Object
-
#initialize(attribute, record, name, *classes) ⇒ ManymanyWrapper
constructor
A new instance of ManymanyWrapper.
Methods inherited from AttributeWrapper
Constructor Details
#initialize(attribute, record, name, *classes) ⇒ ManymanyWrapper
Returns a new instance of ManymanyWrapper.
11 12 13 14 15 16 |
# File 'lib/fauxsql/manymany_wrapper.rb', line 11 def initialize(attribute, record, name, *classes) super(attribute, record, name, {}) = classes. raise ThroughOptionMissing unless [:through] @classes, @through = classes, [:through] end |
Instance Method Details
#<<(other) ⇒ Object
18 19 20 21 22 |
# File 'lib/fauxsql/manymany_wrapper.rb', line 18 def <<(other) raise InvalidManymanyAssociationClass unless @classes.include?(other.class) other.send(@through).clean_push(record) clean_push(other) end |
#delete(*others) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/fauxsql/manymany_wrapper.rb', line 24 def delete(*others) raise InvalidManymanyAssociationClass if (@classes - others.map{|other| other.class }).any? clean_subtract(others) others.each{ |other| other.send(@through).clean_subtract([record]) } # # DataMapper.transaction do # TODO the transaction? others.each{|other| other.save} record.save # end end |