Class: Githu3::Resource
Direct Known Subclasses
Branch, Comment, Commit, Download, Event, GitCommit, Issue, Key, Label, Milestone, Org, Pull, Ref, Repo, Tag, Team, Tree, User
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
#_attributes ⇒ Object
36
37
38
|
# File 'lib/githu3/resource.rb', line 36
def _attributes
@attributes
end
|
#_path ⇒ Object
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
|
#id ⇒ Object
17
18
19
|
# File 'lib/githu3/resource.rb', line 17
def id
@attributes.id
end
|