Class: SimpleScriptRecord

Inherits:
SSHKit::Backend::Printer
  • Object
show all
Defined in:
lib/capsum/sidekiq.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ SimpleScriptRecord

Returns a new instance of SimpleScriptRecord.



59
60
61
62
63
# File 'lib/capsum/sidekiq.rb', line 59

def initialize(&block)
  @result = []
  @block = block
  self.run
end

Instance Attribute Details

#resultObject

Returns the value of attribute result.



57
58
59
# File 'lib/capsum/sidekiq.rb', line 57

def result
  @result
end

Instance Method Details

#command(*args) ⇒ Object

Raises:

  • (SSHKit::Backend::MethodUnavailableError)


93
94
95
# File 'lib/capsum/sidekiq.rb', line 93

def command(*args)
  raise SSHKit::Backend::MethodUnavailableError
end

#execute(*args) ⇒ Object



83
84
85
86
87
# File 'lib/capsum/sidekiq.rb', line 83

def execute(*args)
  options = args.extract_options!
  options.merge!(in: @pwd.nil? ? nil : File.join(@pwd), env: @env, host: @host, user: @user, group: @group)
  @result << [ *args, options ]
end

#test(*args) ⇒ Object

Raises:

  • (SSHKit::Backend::MethodUnavailableError)


89
90
91
# File 'lib/capsum/sidekiq.rb', line 89

def test(*args)
  raise SSHKit::Backend::MethodUnavailableError
end

#to_bashObject



72
73
74
75
76
77
78
79
80
81
# File 'lib/capsum/sidekiq.rb', line 72

def to_bash
  result.map do |args|
    cmd = []
    options = args.extract_options!
    cmd << "cd #{options[:in]} && " if options[:in]
    cmd << args.join(" ")

    cmd.join
  end.join("\n")
end

#within(directory, &block) ⇒ Object



65
66
67
68
69
70
# File 'lib/capsum/sidekiq.rb', line 65

def within(directory, &block)
  (@pwd ||= []).push directory.to_s
  yield
ensure
  @pwd.pop
end