Module: HasResponse

Extended by:
ActiveSupport::Concern
Defined in:
lib/has_response.rb,
lib/has_response/version.rb,
app/concerns/has_response.rb

Constant Summary collapse

VERSION =
'0.0.3'

Instance Method Summary collapse

Instance Method Details

#to_response_with(*attributes) ⇒ Object



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