Class: Devtunnel::Entity
- Inherits:
-
Object
- Object
- Devtunnel::Entity
- Defined in:
- lib/devtunnel/entity.rb
Instance Attribute Summary collapse
-
#list ⇒ Object
Returns the value of attribute list.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#object ⇒ Object
Returns the value of attribute object.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(json) ⇒ Entity
constructor
A new instance of Entity.
Constructor Details
#initialize(json) ⇒ Entity
Returns a new instance of Entity.
8 9 10 11 12 13 14 15 |
# File 'lib/devtunnel/entity.rb', line 8 def initialize(json) self. = json["meta"] if json["meta"] if json["list"] self.list = Entity.build_from_list(json["list"]) else self.object = Entity.build_from_hash(json) end end |
Instance Attribute Details
#list ⇒ Object
Returns the value of attribute list.
6 7 8 |
# File 'lib/devtunnel/entity.rb', line 6 def list @list end |
#meta ⇒ Object
Returns the value of attribute meta.
6 7 8 |
# File 'lib/devtunnel/entity.rb', line 6 def @meta end |
#object ⇒ Object
Returns the value of attribute object.
6 7 8 |
# File 'lib/devtunnel/entity.rb', line 6 def object @object end |
Class Method Details
.build_from_hash(hash) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/devtunnel/entity.rb', line 29 def self.build_from_hash(hash) # our hash should always include a class attribute that we can use # to map back to a proper Entity type # if !hash["success"].nil? and hash.keys.length == 1 return Devtunnel::SuccessResponse.new hash["success"] end hash["new_record"] = false case hash["class"] when "account" Devtunnel::Account.new hash else raise NoSuchEntity.new("Unknown return type in API response data: #{hash["class"]}") end end |
.build_from_list(list) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/devtunnel/entity.rb', line 17 def self.build_from_list(list) list.map do |e| if e.is_a? Hash self.build_from_hash(e) elsif e.is_a? Array self.build_from_list(e) else # TODO: throw some weird entity error end end end |