Method: Sawyer::Resource#initialize

Defined in:
lib/sawyer/resource.rb

#initialize(agent, data = {}) ⇒ Resource

Initializes a Resource with the given data.

agent - The Sawyer::Agent that made the API request. data - Hash of key/value properties.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sawyer/resource.rb', line 12

def initialize(agent, data = {})
  @_agent  = agent
  data, links = agent.parse_links(data)
  @_rels = Relation.from_links(agent, links)
  @_fields = Set.new
  @_metaclass = (class << self; self; end)
  @attrs = {}
  data.each do |key, value|
    @_fields << key
    @attrs[key.to_sym] = process_value(value)
  end
  @_metaclass.send(:attr_accessor, *data.keys)
end