Class: Modulr::Resources::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/modulr/resources/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, attributes = {}) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
15
# File 'lib/modulr/resources/base.rb', line 8

def initialize(response, attributes = {})
  @response = response

  attributes.each do |key, value|
    m = "#{key}=".to_sym
    send(m, value) if respond_to?(m)
  end
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/modulr/resources/base.rb', line 6

def response
  @response
end

Class Method Details

.map(original_attribute, mapped_attributes = nil) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/modulr/resources/base.rb', line 17

def self.map(original_attribute, mapped_attributes = nil)
  class_eval { attr_writer original_attribute.to_sym }
  mapped_attributes ||= original_attribute
  mapped_attributes = [mapped_attributes].flatten
  mapped_attributes.each do |mapped_attribute|
    define_method(mapped_attribute) { instance_variable_get("@#{original_attribute}") }
  end
end