Class: Synchronisable::DataBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/synchronisable/data_builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, synchronizer) ⇒ DataBuilder

Returns a new instance of DataBuilder.



11
12
13
14
# File 'lib/synchronisable/data_builder.rb', line 11

def initialize(model, synchronizer)
  @model = model
  @synchronizer = synchronizer
end

Class Method Details

.build(model, synchronizer, data) ⇒ Object



6
7
8
# File 'lib/synchronisable/data_builder.rb', line 6

def build(model, synchronizer, data)
  new(model, synchronizer).build(data)
end

Instance Method Details

#build(data) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/synchronisable/data_builder.rb', line 16

def build(data)
  input = InputDescriptor.new(data)

  result = case input
  when ->(i) { i.empty? }
    @synchronizer.fetch
  when ->(i) { i.remote_id? }
    @synchronizer.find(data)
  when ->(i) { i.local_id? }
    find_by_local_id(data)
  when ->(i) { i.array_of_ids? }
    find_by_array_of_ids(input)
  else
    result = data.dup
  end

  [result].flatten.compact
end