Class: GitFeats::Args

Inherits:
Array
  • Object
show all
Defined in:
lib/git-feats/args.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Args

Makes a new Args object



5
6
7
8
# File 'lib/git-feats/args.rb', line 5

def initialize(*args)
  super
  @executable = ENV["GIT"] || "git"
end

Instance Method Details

#match?(pattern) ⇒ Boolean

Checks if a pattern (string of args) matches the first arguments in an Args object

Examples:

Args(‘init’).match?(‘init’) #=> true Args(‘add’, ‘.’).match?(‘add .’) #=> true Args(‘commit’, ‘-a’, ‘-m’).match?(‘commit -a’) #=> true

Args(‘commit’).match?(‘init’) #=> false Args(‘commit’).match?(‘commit -a’) #=> false

Returns a boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'lib/git-feats/args.rb', line 33

def match?(pattern)
  pattern.split.each_with_index do |arg, index|
    return false unless arg == self[index]
  end
  return true
end

#to_exec(args = self) ⇒ Object

Returns an executable command that can be called with exec

args - The args of the command

Returns an array of args prepended with an executable



16
17
18
# File 'lib/git-feats/args.rb', line 16

def to_exec(args = self)
  Array(@executable) + args
end