Module: Synchronisable::Model::Methods

Defined in:
lib/synchronisable/model/methods.rb

Overview

Methods that will be attached to synchronisable model class.

Instance Method Summary collapse

Instance Method Details

#imports_countObject

Count of import records for this model.


63
64
65
# File 'lib/synchronisable/model/methods.rb', line 63

def imports_count
  Import.where(synchronisable_type: self).count
end

#sync(data, options) ⇒ Object #sync(options) ⇒ Object #sync(data) ⇒ Object #syncObject

Creates a new controller, that initiates synchronization for this particular model and its associations. If you have implemented `fetch` & `find` methods in your model synchronizer, than it will be used if no data supplied.

Examples:

Supplying array of hashes with remote attributes

FooModel.sync([
  {
    :id => '123',
    :attr1 => 4,
    :attr2 => 'blah'
  },
  ...
])

General usage

FooModel.sync(:includes => {
  :assocation_model => :nested_association_model
})

Football domain use case

Match.sync(:includes => {
  :match_players => :player
})

Here is all possible ways to call #sync

Model.sync
Model.sync({ :a1 => 1, :a2 => 2 })
Model.sync({ :includes => {...}, :parent => xxx })
Model.sync(123)
Model.sync('asdf')
Model.sync([{ :a1 => 1, :a2 => 2 }, { :a1 => 3, :a2 => 4 }, ...])
Model.sync([123, 345, 456])
Model.sync(['123', '345', '456'])

Overloads:

  • #sync(data, options) ⇒ Object

    Parameters:

    • data (Hash, Array<Hash>, Array<String>, Array<Integer>, String, Integer)

      synchronization data

    • options (Hash)

      synchronization options

    Options Hash (options):

    • :includes (Hash)

      assocations to be synchronized. Use this option to override `has_one` & `has_many` assocations defined in model synchronizer.

See Also:


58
59
60
# File 'lib/synchronisable/model/methods.rb', line 58

def sync(*args)
  Controller.call(self, *args)
end

#synchronisable?Boolean

Returns:

  • (Boolean)

8
9
10
# File 'lib/synchronisable/model/methods.rb', line 8

def synchronisable?
  true
end