class Command
Describe a command
Command
is able to run itself.
Attributes
config[R]
@return [Hash]
parts[R]
@return [Array<String>]
Private Class Methods
new(command, config = {}, extra = nil)
click to toggle source
@param [Array<String>] command @param [Hash] config @param [String|nil] extra
# File lib/kamaze/docker_image/command.rb, line 23 def initialize(command, config = {}, extra = nil) command.clone.to_a.tap do |c| extras = Shellwords.split(extra.to_s).compact @parts = c.push(*extras).freeze end config.clone.to_h.tap do |c| @config = c.freeze end end
Private Instance Methods
execute()
click to toggle source
@return [Boolean]
# File lib/kamaze/docker_image/command.rb, line 51 def execute system(*self.to_a) end
run(&block)
click to toggle source
# File lib/kamaze/docker_image/command.rb, line 44 def run(&block) sh(*self.to_a, &block) end
Also aliased as: call
sh(*cmd, &block)
click to toggle source
@see github.com/ruby/rake/blob/124a03bf4c0db41cd80a41394a9e7c6426e44784/lib/rake/file_utils.rb#L43
# File lib/kamaze/docker_image/command.rb, line 73 def sh(*cmd, &block) options = cmd.last.is_a?(Hash) ? cmd.pop : {} options[:verbose] = config[:verbose] unless options.key?(:verbose) utils.sh(*cmd.map(&:to_s).push(options), &block) end
to_a()
click to toggle source
@return [Array<String>]
# File lib/kamaze/docker_image/command.rb, line 35 def to_a parts.clone end
to_s()
click to toggle source
@return [String]
# File lib/kamaze/docker_image/command.rb, line 40 def to_s Shellwords.join(self.to_a) end
utils()
click to toggle source
Get utils.
return [Class]
# File lib/kamaze/docker_image/command.rb, line 63 def utils if Gem::Specification.find_all_by_name('rake') require 'rake' require 'rake/file_utils' end Class.new { include FileUtils }.new end