Class: Synchronisable::Source
- Inherits:
-
Object
- Object
- Synchronisable::Source
- Defined in:
- lib/synchronisable/source.rb
Overview
Synchronization source.
Instance Attribute Summary collapse
-
#associations ⇒ Object
readonly
Returns the value of attribute associations.
-
#import_record ⇒ Object
Returns the value of attribute import_record.
-
#local_attrs ⇒ Object
readonly
Returns the value of attribute local_attrs.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#remote_attrs ⇒ Object
readonly
Returns the value of attribute remote_attrs.
-
#remote_id ⇒ Object
readonly
Returns the value of attribute remote_id.
Instance Method Summary collapse
-
#build ⇒ Object
private
Extracts the ‘remote_id` from remote attributes, maps remote attirubtes to local attributes and tries to find import record for given model by extracted remote id.
- #dump_message ⇒ Object
-
#initialize(model, parent, remote_attrs) ⇒ Source
constructor
A new instance of Source.
- #local_record ⇒ Object
- #updatable? ⇒ Boolean
Constructor Details
#initialize(model, parent, remote_attrs) ⇒ Source
8 9 10 11 |
# File 'lib/synchronisable/source.rb', line 8 def initialize(model, parent, remote_attrs) @model, @parent, @synchronizer = model, parent, model.synchronizer @remote_attrs = remote_attrs.with_indifferent_access end |
Instance Attribute Details
#associations ⇒ Object (readonly)
Returns the value of attribute associations.
5 6 7 |
# File 'lib/synchronisable/source.rb', line 5 def associations @associations end |
#import_record ⇒ Object
Returns the value of attribute import_record.
4 5 6 |
# File 'lib/synchronisable/source.rb', line 4 def import_record @import_record end |
#local_attrs ⇒ Object (readonly)
Returns the value of attribute local_attrs.
5 6 7 |
# File 'lib/synchronisable/source.rb', line 5 def local_attrs @local_attrs end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/synchronisable/source.rb', line 5 def model @model end |
#remote_attrs ⇒ Object (readonly)
Returns the value of attribute remote_attrs.
5 6 7 |
# File 'lib/synchronisable/source.rb', line 5 def remote_attrs @remote_attrs end |
#remote_id ⇒ Object (readonly)
Returns the value of attribute remote_id.
5 6 7 |
# File 'lib/synchronisable/source.rb', line 5 def remote_id @remote_id end |
Instance Method Details
#build ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Extracts the ‘remote_id` from remote attributes, maps remote attirubtes to local attributes and tries to find import record for given model by extracted remote id.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/synchronisable/source.rb', line 18 def build @remote_id = @synchronizer.extract_remote_id(@remote_attrs) @local_attrs = @synchronizer.map_attributes(@remote_attrs) @associations = @synchronizer.associations_for(@local_attrs) @local_attrs.delete_if do |key, _| @associations.keys.any? { |a| a.key == key } end @import_record = Import.find_by( :remote_id => @remote_id, :synchronisable_type => @model ) set_parent_attribute end |
#dump_message ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/synchronisable/source.rb', line 43 def %Q( remote_id: #{remote_id}, remote attributes: #{remote_attrs}, local attributes: #{local_attrs} ) end |
#local_record ⇒ Object
39 40 41 |
# File 'lib/synchronisable/source.rb', line 39 def local_record @import_record.try(:synchronisable) end |
#updatable? ⇒ Boolean
35 36 37 |
# File 'lib/synchronisable/source.rb', line 35 def updatable? @import_record.present? && local_record.present? end |