8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/rest_model/source/sender.rb', line 8
def to_source(options = {})
source = {}
errors = {}
root_options = {without_nil: options[:without_nil], fail: options[:fail]}
keys_to_source(options).each do |key|
value = __send__(key.name)
key_options = options.fetch(key.name, {}).merge(root_options)
begin
source.merge! key.to_source!(value, self, key_options)
rescue TranslationError, SerializationError => e
errors[key.name] = e.message
rescue SourceError => e
errors.merge!(e.message)
end
end
fail SourceError, errors unless errors.empty? if options[:fail]
source.with_indifferent_access
end
|