Class: Capillary::RefCollection
- Inherits:
-
Object
- Object
- Capillary::RefCollection
show all
- Defined in:
- lib/capillary/ref_collection.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of RefCollection.
22
23
24
25
26
27
28
|
# File 'lib/capillary/ref_collection.rb', line 22
def initialize
@refs = {
"heads" => [],
"tags" => [],
"remotes" => {}
}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
61
62
63
64
65
|
# File 'lib/capillary/ref_collection.rb', line 61
def method_missing(method, *args, &block)
key = method.to_s
return super if !@refs.key?(key) || args.length != 0
@refs[key]
end
|
Class Method Details
.parse(ref) ⇒ Object
30
31
32
33
34
|
# File 'lib/capillary/ref_collection.rb', line 30
def self.parse(ref)
refs = new
refs.parse(ref)
refs
end
|
Instance Method Details
#<<(full_ref) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/capillary/ref_collection.rb', line 41
def <<(full_ref)
refs, type, *name = full_ref.strip.split("/")
return if type.nil?
type = type.gsub("-", "_")
if type == "remotes"
append_array_in_hash(@refs[type], name.shift, name)
else
append_array_in_hash(@refs, type, name)
end
end
|
#parse(ref) ⇒ Object
36
37
38
39
|
# File 'lib/capillary/ref_collection.rb', line 36
def parse(ref)
return if ref.nil? || ref == ""
ref.gsub(/[\(\)]/,"").split(/,\s?/).each { |r| self << r }
end
|
#to_hash ⇒ Object
53
54
55
|
# File 'lib/capillary/ref_collection.rb', line 53
def to_hash
@refs.dup
end
|
#to_json ⇒ Object
57
58
59
|
# File 'lib/capillary/ref_collection.rb', line 57
def to_json
JSON.unparse(@refs)
end
|