Class: GitHubV3API::Entity
- Inherits:
-
Object
- Object
- GitHubV3API::Entity
- Defined in:
- lib/github_v3_api/entity.rb
Overview
This is the base class used for value objects returned by the API. See descendent classes for more details.
Class Method Summary (collapse)
-
+ (Object) attr_reader(*fields)
:nodoc:.
-
+ (Object) new_with_all_data(api, data)
:nodoc:.
Instance Method Summary (collapse)
-
- (Object) [](key)
:nodoc:.
-
- (Entity) initialize(api, data)
constructor
api
an instance of the API class associated with the subclass of.
-
- (Object) initialize_fetched(api, data)
:nodoc:.
Constructor Details
- (Entity) initialize(api, data)
api |
an instance of the API class associated with the subclass of Entity being instantiated. |
data |
a Hash with keys corresponding to the data fields for the subclass of Entity being instantiated |
15 16 17 18 |
# File 'lib/github_v3_api/entity.rb', line 15 def initialize(api, data) @api = api @data = data end |
Class Method Details
+ (Object) attr_reader(*fields)
:nodoc:
32 33 34 35 36 37 38 |
# File 'lib/github_v3_api/entity.rb', line 32 def self.attr_reader(*fields) #:nodoc: fields.each do |field| define_method field do self[field.to_s] end end end |
+ (Object) new_with_all_data(api, data)
:nodoc:
5 6 7 8 9 |
# File 'lib/github_v3_api/entity.rb', line 5 def self.new_with_all_data(api, data) #:nodoc: entity = allocate entity.initialize_fetched(api, data) entity end |
Instance Method Details
- (Object) [](key)
:nodoc:
25 26 27 28 29 30 |
# File 'lib/github_v3_api/entity.rb', line 25 def [](key) #:nodoc: if @data[key].nil? && !@fetched fetch_data end @data[key] end |
- (Object) initialize_fetched(api, data)
:nodoc:
20 21 22 23 |
# File 'lib/github_v3_api/entity.rb', line 20 def initialize_fetched(api, data) #:nodoc: initialize(api, data) @fetched = true end |