Class: Brio::Resources::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/brio/resources/resource.rb

Direct Known Subclasses

Post, User

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr_hash = {}) ⇒ Resource

Returns a new instance of Resource.



5
6
7
8
9
10
# File 'lib/brio/resources/resource.rb', line 5

def initialize( attr_hash={} )
  attr_hash.map do |(k,v)|
    writer_m = "#{k}="
    public_send("#{k}=", v) if respond_to? writer_m
  end
end

Class Method Details

.create_from_json(json) ⇒ Object



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

def self.create_from_json( json )
  if json['data']
    if json['data'].kind_of? Array 
      json['data'].map{ |post| self.new post }.reverse
    else
      self.new json['data']
    end
  else
    NullResource.new json['meta']
  end
end