Class: RTrail::Entity
Overview
Base class for RTrail objects
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Class Method Summary collapse
-
.basename ⇒ Object
Return the plain lowercase name of the derived class, ex.
- .client ⇒ Object
- .client=(client) ⇒ Object
Instance Method Summary collapse
-
#add_entity(klass, parent_id, params = {}) ⇒ Object
Add a new entity by invoking POST ‘add_<thing>/<id>`.
- #client ⇒ Object
-
#fetch(id) ⇒ Object
Fetch data for a derived class object.
-
#get_entities(klass, parent_id, params = {}) ⇒ Object
Return a list of entities retrieved from ‘get_<thing>s/<id>`.
-
#initialize(id_or_data) ⇒ Entity
constructor
A new instance of Entity.
-
#method_missing(meth, *args, &block) ⇒ Object
Pass-through to Hashie::Mash for attribute access.
Methods included from Helpers
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
Pass-through to Hashie::Mash for attribute access
44 45 46 |
# File 'lib/rtrail/entity.rb', line 44 def method_missing(meth, *args, &block) return data.send(meth, *args, &block) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
36 37 38 |
# File 'lib/rtrail/entity.rb', line 36 def data @data end |
Class Method Details
.basename ⇒ Object
Return the plain lowercase name of the derived class, ex. “project”, “suite”, “case”, suitable for passing to the ‘get_*` API methods.
20 21 22 |
# File 'lib/rtrail/entity.rb', line 20 def basename return self.name.downcase.gsub(/^.*::/, '') end |
.client ⇒ Object
13 14 15 |
# File 'lib/rtrail/entity.rb', line 13 def client @@client end |
.client=(client) ⇒ Object
9 10 11 |
# File 'lib/rtrail/entity.rb', line 9 def client=(client) @@client = client end |
Instance Method Details
#add_entity(klass, parent_id, params = {}) ⇒ Object
Add a new entity by invoking POST ‘add_<thing>/<id>`.
59 60 61 62 |
# File 'lib/rtrail/entity.rb', line 59 def add_entity(klass, parent_id, params={}) path = "add_#{klass.basename}/#{parent_id}" return klass.new(client.post(path, params)) end |
#client ⇒ Object
25 26 27 |
# File 'lib/rtrail/entity.rb', line 25 def client return self.class.client end |
#fetch(id) ⇒ Object
Fetch data for a derived class object.
39 40 41 |
# File 'lib/rtrail/entity.rb', line 39 def fetch(id) return client.get("get_#{self.class.basename}/#{id}") end |
#get_entities(klass, parent_id, params = {}) ⇒ Object
Return a list of entities retrieved from ‘get_<thing>s/<id>`.
49 50 51 52 53 54 55 56 |
# File 'lib/rtrail/entity.rb', line 49 def get_entities(klass, parent_id, params={}) path = path_with_params( "get_#{klass.basename}s/#{parent_id}", params) return client.get(path).map do |data| klass.new(data) end end |