Class: Githu3::Resource

Inherits:
Object
  • Object
show all
Extended by:
Relations
Defined in:
lib/githu3/resource.rb

Instance Method Summary collapse

Methods included from Relations

embeds_many, embeds_one, has_many

Constructor Details

#initialize(d, client) ⇒ Resource

Returns a new instance of Resource.



7
8
9
10
11
12
13
14
15
# File 'lib/githu3/resource.rb', line 7

def initialize(d, client)
  @client = client
  
  if d.is_a?(String)
    @attributes = Githu3::Store.new(client.get(d).body)
  else
    @attributes = Githu3::Store.new(d)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object



30
31
32
33
34
# File 'lib/githu3/resource.rb', line 30

def method_missing m, *args
  val = @attributes.send(m, *args)
  time_val = Time.parse(val) if m =~ /_at$/ rescue nil
  time_val || val
end

Instance Method Details

#_attributesObject



36
37
38
# File 'lib/githu3/resource.rb', line 36

def _attributes
  @attributes
end

#_pathObject



25
26
27
28
# File 'lib/githu3/resource.rb', line 25

def _path
  return if url.nil?
  URI.parse(url).path
end

#get(*args) ⇒ Object



21
22
23
# File 'lib/githu3/resource.rb', line 21

def get *args
  @client.get(*args)
end

#idObject



17
18
19
# File 'lib/githu3/resource.rb', line 17

def id
  @attributes.id
end