class Capillary::RefCollection
Public Class Methods
new()
click to toggle source
# File lib/capillary/ref_collection.rb, line 21 def initialize @refs = { "heads" => [], "tags" => [], "remotes" => {} } end
parse(ref)
click to toggle source
# File lib/capillary/ref_collection.rb, line 29 def self.parse(ref) refs = new refs.parse(ref) refs end
Public Instance Methods
<<(full_ref)
click to toggle source
# File lib/capillary/ref_collection.rb, line 40 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
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/capillary/ref_collection.rb, line 60 def method_missing(method, *args, &block) key = method.to_s return super if !@refs.key?(key) || args.length != 0 @refs[key] end
parse(ref)
click to toggle source
# File lib/capillary/ref_collection.rb, line 35 def parse(ref) return if ref.nil? || ref == "" ref.gsub(/[\(\)]/,"").split(/,\s?/).each { |r| self << escape(r) } end
to_hash()
click to toggle source
# File lib/capillary/ref_collection.rb, line 52 def to_hash @refs.dup end
to_json()
click to toggle source
# File lib/capillary/ref_collection.rb, line 56 def to_json JSON.unparse(@refs) end
Private Instance Methods
append_array_in_hash(hash, key, names)
click to toggle source
# File lib/capillary/ref_collection.rb, line 71 def append_array_in_hash(hash, key, names) hash[key] ||= [] hash[key] << names.join("/") end
escape(str)
click to toggle source
# File lib/capillary/ref_collection.rb, line 67 def escape(str) HTMLEntities.new.encode(str) end