Class: MultiGit::RefSpec::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/multi_git/refspec.rb

Constant Summary collapse

REF =
%r{\A(\+?)([a-zA-Z/0-9_*]+)?(?:(:)([a-zA-Z/0-9_*]+)?)?\z}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from_base = 'refs/heads/', to_base) ⇒ Parser

Returns a new instance of Parser.



47
48
49
50
# File 'lib/multi_git/refspec.rb', line 47

def initialize(from_base = 'refs/heads/', to_base )
  @from_base = from_base
  @to_base = to_base
end

Instance Attribute Details

#from_baseObject (readonly)

Returns the value of attribute from_base.



45
46
47
# File 'lib/multi_git/refspec.rb', line 45

def from_base
  @from_base
end

Instance Method Details

#[](*args) ⇒ Array<RefSpec> #[](*args, options) ⇒ Array<RefSpec>

Overloads:

  • #[](*args) ⇒ Array<RefSpec>

    Parameters:

    • args (RefSpec, String, Hash, Range, ...)

    Returns:

  • #[](*args, options) ⇒ Array<RefSpec>

    Parameters:

    • args (RefSpec, String, Hash, Range, ...)
    • options (Hash)

    Options Hash (options):

    • :forced (Boolean) — default: false

    Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/multi_git/refspec.rb', line 61

def [](*args)
  forced = false
  if args.last.kind_of? Hash
    options = args.pop.dup
    forced = options.delete(:forced){ false }
    args << options
  end
  args.collect_concat do |arg|
    if arg.kind_of? RefSpec
      [arg]
    elsif arg.kind_of? String
      [parse_string(arg, forced)]
    elsif arg.kind_of? Hash
      arg.map{|k,v| parse_pair(k,v, forced) }
    elsif arg.kind_of? Range
      [parse_pair(arg.begin, arg.end, forced)]
    else
      raise ArgumentError, "Expected a String, Hash or Range. Got #{arg.inspect}"
    end
  end
end