Class: Synchronisable::InputParser Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Responsible for guessing the user input format.

Instance Method Summary collapse

Constructor Details

#initialize(model, synchronizer) ⇒ InputParser

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.

Returns a new instance of InputParser.



8
9
10
11
# File 'lib/synchronisable/input_parser.rb', line 8

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

Instance Method Details

#parse(data) ⇒ Array<Hash>

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.

Parses the user input.

Parameters:

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

    synchronization data to handle.

Returns:

  • (Array<Hash>)

    array of hashes with remote attributes



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/synchronisable/input_parser.rb', line 19

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

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

  [result].flatten.compact
end