Class: OpenSesame::Github::Base

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

Direct Known Subclasses

Collection, Organization, TeamMember

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) {|_self| ... } ⇒ Base

Public: Instantiate a new Github::TeamMember from api attributes.

attributes - hash of api github team member attributes

Examples

Github::TeamMember.new(
  "gravatar_id"=>"f009205a899da22248cca0b772aec9c9",
  "url"=>"https://api.github.com/users/defunkt",
  "avatar_url"=>"https://secure.gravatar.com/avatar/abcd1234.png",
  "id"=>2,
  "login"=>"defunkt"
 )
# => <Github::TeamMember>

Returns new Github::TeamMember.

Yields:

  • (_self)

Yield Parameters:



41
42
43
44
# File 'lib/opensesame/github/base.rb', line 41

def initialize(attributes = {})
  @attributes = attributes
  yield self if block_given?
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



23
24
25
# File 'lib/opensesame/github/base.rb', line 23

def attributes
  @attributes
end

Class Method Details

.lazy_attr_reader(*attrs) ⇒ Object

Public: Define readers from attributes hash

symbol(s) - Method name

Examples

lazy_attr_reader :id, :login


13
14
15
16
17
18
19
20
21
# File 'lib/opensesame/github/base.rb', line 13

def self.lazy_attr_reader(*attrs)
  attrs.each do |attribute|
    class_eval do
      define_method(attribute) do
        @attributes[attribute.to_s] || @attributes[attribute] # allow string or symbol access
      end
    end
  end
end

Instance Method Details

#==(other) ⇒ Object



46
47
48
# File 'lib/opensesame/github/base.rb', line 46

def ==(other)
  super || (other.class == self.class && other.id == self.id)
end

#get(*args) ⇒ Object



50
51
52
# File 'lib/opensesame/github/base.rb', line 50

def get(*args)
  OpenSesame::Github.api.get(*args)
end