lib/synchronisable/input_parser.rb in synchronisable-1.0.6 vs lib/synchronisable/input_parser.rb in synchronisable-1.0.7

- old
+ new

@@ -20,12 +20,14 @@ # @return [Array<Hash>] array of hashes with remote attributes def parse(data) input = InputDescriptor.new(data) result = case - when input.empty? || input.params? - @synchronizer.fetch(data || {}) + when input.empty? + @synchronizer.fetch + when input.params? + find_or_fetch_by_data(input.data) when input.remote_id? @synchronizer.find(data) when input.local_id? find_by_local_id(data) when input.array_of_ids? @@ -36,9 +38,14 @@ [result].flatten.compact end private + + def find_or_fetch_by_data(data) + sync_method = data.key?(:id) ? :find : :fetch + @synchronizer.send(sync_method, data) + end def find_by_array_of_ids(input) records = find_imports(input.element_class.name, input.data) records.map { |r| @synchronizer.find(r.remote_id) } end