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.

Parameters:

  • attrs (Hash)

    local record attributes

Returns:

  • (Hash<Synchronisable::Association, Array>)

    associations hash

Raises:

  • (MissedAssocationsError)

    raised when the given attributes hash doesn't required associations


33
34
35
36
37
38
# File 'lib/synchronisable/dsl/associations.rb', line 33

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


14
15
16
17
# File 'lib/synchronisable/dsl/associations.rb', line 14

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