Class: BetweenMeals::Cmd

Inherits:
Object
  • Object
show all
Defined in:
lib/between_meals/cmd.rb

Direct Known Subclasses

Repo::Git::Cmd, Repo::Hg::Cmd, Repo::Svn::Cmd

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Cmd

Returns a new instance of Cmd.



23
24
25
26
27
# File 'lib/between_meals/cmd.rb', line 23

def initialize(params)
  @bin = params[:bin] || fail
  @cwd = params[:cwd] || Dir.pwd
  @logger = params[:logger] || Logger.new(STDOUT)
end

Instance Attribute Details

#binObject

Returns the value of attribute bin.



21
22
23
# File 'lib/between_meals/cmd.rb', line 21

def bin
  @bin
end

Instance Method Details

#cmd(params, cwd = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/between_meals/cmd.rb', line 29

def cmd(params, cwd = nil)
  cwd ||= File.expand_path(@cwd)
  cmd = "#{@bin} #{params}"
  @logger.info("Running \"#{cmd}\"")
  c = Mixlib::ShellOut.new(
    cmd,
    :cwd => cwd,
  )
  # macOS needs /usr/local/bin as hg cannot be installed in /bin or /usr/bin
  c.environment = {
    'PATH' => '/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin',
  }
  c.run_command
  c.error!
  c
end