Class: GitHub::Hash
- Inherits:
-
Hash
show all
- Defined in:
- lib/ruby-github.rb
Overview
Instance Method Summary
collapse
Constructor Details
#initialize(hash = nil, user = nil, repo = nil, obj = nil) ⇒ Hash
Returns a new instance of Hash.
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/ruby-github.rb', line 34
def initialize(hash = nil, user = nil, repo = nil, obj = nil)
super(obj)
@user = user
@repo = repo
if hash && hash.is_a?(Hash)
hash.each do |k,v|
v = ::GitHub::Hash.new(v,user,repo,obj) if v.is_a?(Hash) && !v.is_a?(::GitHub::Hash)
if v.is_a?(Array)
v = v.collect{|potential_hash|
potential_hash = ::GitHub::Hash.new(potential_hash,user,repo,obj) if potential_hash.is_a?(Hash) && !potential_hash.is_a?(::GitHub::Hash)
potential_hash
}
end
self[k] = v
end
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/ruby-github.rb', line 68
def method_missing(method_name, *args)
if (match = method_name.to_s.match(/(.*)=$/)) && args.size == 1
self[match[1]] = args.first
elsif keys.include?(method_name.to_s)
self[method_name]
elsif method_name.to_s == "commits" && self["name"] && self["url"]
GitHub.commits(@user, name)
elsif method_name.to_s == "detailed" && self["id"] && self["message"]
GitHub.commit(@user,@repo,self["id"])
else
super
end
end
|
Instance Method Details
#[](key) ⇒ Object
58
59
60
61
|
# File 'lib/ruby-github.rb', line 58
def [](key)
key = key.to_s
super
end
|
#[]=(key, value) ⇒ Object
63
64
65
66
|
# File 'lib/ruby-github.rb', line 63
def []=(key,value)
key = key.to_s
super
end
|
#id ⇒ Object
54
55
56
|
# File 'lib/ruby-github.rb', line 54
def id
self["id"] ? self["id"] : super
end
|