4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'app/concerns/has_response.rb', line 4
def to_response_with(*attributes)
raise "Class `#{self.class.name}' does not have a `to_response' method defined" if !respond_to?(:to_response)
response = self.to_response
attributes.each do |attribute|
if attribute.is_a?(Hash)
attribute.each do |key, value|
response[format_response_key(key)] = format_response_value(self.send(key), value)
end
elsif attribute.is_a?(Array)
attribute.each do |key|
response[format_response_key(key)] = format_response_value(self.send(key))
end
elsif attribute.is_a?(Symbol)
response[format_response_key(attribute)] = format_response_value(self.send(attribute))
end
end
response
end
|