Class: Brio::Resources::Resource
- Inherits:
-
Object
- Object
- Brio::Resources::Resource
- Defined in:
- lib/brio/resources/resource.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attr_hash = {}) ⇒ Resource
constructor
A new instance of Resource.
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 |