Module: Synchronisable::DSL::Associations::ClassMethods

Defined in:
lib/synchronisable/dsl/associations.rb

Instance Method Summary collapse

Instance Method Details

#associations_for(attrs) ⇒ Hash<Synchronisable::Association, Array>

Builds hash with association as key and array of ids as value.

Raises:

  • (MissedAssocationsError)

    raised when the given attributes hash doesn’t required associations



36
37
38
39
40
41
# File 'lib/synchronisable/dsl/associations.rb', line 36

def associations_for(attrs)
  ensure_required_associations(attrs)

  intersection = self.associations.map { |key, _| key } & attrs.keys
  Hash[intersection.map { |key| [self.associations[key], [*attrs[key]]] }]
end

#inherited(subclass) ⇒ Object



16
17
18
19
# File 'lib/synchronisable/dsl/associations.rb', line 16

def inherited(subclass)
  super
  subclass.associations = {}
end