21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/well_formed/attribute_assignment.rb', line 21
def assign_attributes_to(resource)
matched = attributes.select { |attr, _| resource.respond_to?("#{attr}=") }
unmatched_keys = attributes.keys - matched.keys
if unmatched_keys.any?
case self.class.unmatched_attributes_policy
when :warn
warn "#{self.class} has attributes with no setter on resource: #{unmatched_keys.join(", ")}"
when :raise
raise UnmatchedAttributesError,
"#{self.class} has attributes with no setter on resource: #{unmatched_keys.join(", ")}"
end
end
if resource.respond_to?(:assign_attributes)
resource.assign_attributes(matched)
else
matched.each { |attr, value| resource.public_send(:"#{attr}=", value) }
end
end
|