Class: OctocatHerder::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/octocat_herder/base.rb

Direct Known Subclasses

PullRequest, PullRequest::Repo, Repository, User

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_hash, conn = OctocatHerder::Connection.new) ⇒ Base

Returns a new instance of Base.



12
13
14
15
# File 'lib/octocat_herder/base.rb', line 12

def initialize(raw_hash, conn = OctocatHerder::Connection.new)
  @connection = conn
  @raw = raw_hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *args) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/octocat_herder/base.rb', line 17

def method_missing(id, *args)
  unless @raw and @raw.keys.include?(id.id2name)
    raise NoMethodError.new("undefined method #{id.id2name} for #{self}:#{self.class}")
  end

  @raw[id.id2name]
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



10
11
12
# File 'lib/octocat_herder/base.rb', line 10

def connection
  @connection
end

#rawObject (readonly)

Returns the value of attribute raw.



10
11
12
# File 'lib/octocat_herder/base.rb', line 10

def raw
  @raw
end

Instance Method Details

#available_attributesObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/octocat_herder/base.rb', line 25

def available_attributes
  attrs = []
  attrs += @raw.keys.reject do |k|
    [
      'id',
      'type',
    ].include? k
  end if @raw

  (attrs + additional_attributes).uniq
end