Class: Git::Gsub::Commands::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/git/gsub.rb

Direct Known Subclasses

Gsub, Rename

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to, paths = [], options = {}) ⇒ Command



73
74
75
76
77
78
# File 'lib/git/gsub.rb', line 73

def initialize(from, to, paths = [], options = {})
  @from = from
  @to = to
  @paths = paths
  @options = options
end

Instance Attribute Details

#fromObject

Returns the value of attribute from.



71
72
73
# File 'lib/git/gsub.rb', line 71

def from
  @from
end

#optionsObject

Returns the value of attribute options.



71
72
73
# File 'lib/git/gsub.rb', line 71

def options
  @options
end

#pathsObject

Returns the value of attribute paths.



71
72
73
# File 'lib/git/gsub.rb', line 71

def paths
  @paths
end

#toObject

Returns the value of attribute to.



71
72
73
# File 'lib/git/gsub.rb', line 71

def to
  @to
end

Instance Method Details

#argsObject



88
89
90
91
92
93
94
95
96
# File 'lib/git/gsub.rb', line 88

def args
  args = []
  args << [from, to]
  args << [from.camelcase, to.camelcase] if options[:camel]
  args << [from.underscore, to.underscore] if options[:snake]
  args << [from.underscore.dasherize, to.underscore.dasherize] if options[:kebab]

  args.compact
end

#run_commands(commands) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/git/gsub.rb', line 80

def run_commands(commands)
  if options[:dry]
    commands.each { |args| puts Array(args).join(' ') }
  else
    commands.each { |args| Open3.capture3(*args) }
  end
end