Class: Geni::Base
- Inherits:
-
Object
- Object
- Geni::Base
- Defined in:
- lib/geni/base.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #fetch ⇒ Object
- #fetched? ⇒ Boolean
-
#initialize(params = {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(params = {}) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/geni/base.rb', line 5 def initialize(params = {}) @id = params[:id] @client = params[:client] @fetched = params[:fetched] || false if params.has_key?(:attrs) params[:attrs].each_pair do |key, value| instance_variable_set("@#{key}", value) end end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/geni/base.rb', line 3 def client @client end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/geni/base.rb', line 3 def id @id end |
Class Method Details
.has_fetchable_attributes(attribute_names) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/geni/base.rb', line 29 def has_fetchable_attributes(attribute_names) attribute_names.each do |attribute_name| define_method "#{attribute_name}" do self.fetch unless self.fetched? instance_variable_get("@#{attribute_name}") end end end |
Instance Method Details
#fetch ⇒ Object
21 22 23 24 25 26 |
# File 'lib/geni/base.rb', line 21 def fetch client.access_token.get("/api/#{id}").each_pair do |attr, value| instance_variable_set("@#{attr}".to_sym, value) end @fetched = true end |
#fetched? ⇒ Boolean
17 18 19 |
# File 'lib/geni/base.rb', line 17 def fetched? @fetched end |