Class: GitHubV3API::Entity

Inherits:
Object
  • Object
show all
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.

Direct Known Subclasses

Issue, Org, Repo, User

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, data) ⇒ Entity

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

.attr_reader(*fields) ⇒ Object

: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

.new_with_all_data(api, data) ⇒ Object

: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

#[](key) ⇒ Object

: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

#initialize_fetched(api, data) ⇒ Object

: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