Class: Kamaze::DockerImage::Command
- Inherits:
-
Object
- Object
- Kamaze::DockerImage::Command
- Defined in:
- lib/kamaze/docker_image/command.rb
Overview
Describe a command
Command is able to run itself.
Instance Attribute Summary collapse
- #config ⇒ Hash readonly
- #parts ⇒ Array<String> readonly protected
Instance Method Summary collapse
- #execute ⇒ Boolean
-
#initialize(command, config = {}, extra = nil) ⇒ Command
constructor
A new instance of Command.
- #run(&block) ⇒ Object (also: #call)
- #sh(*cmd, &block) ⇒ Object protected
- #to_a ⇒ Array<String>
- #to_s ⇒ String
-
#utils ⇒ Object
protected
Get utils.
Constructor Details
#initialize(command, config = {}, extra = nil) ⇒ Command
Returns a new instance of Command.
23 24 25 26 27 28 29 30 31 32 |
# 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 |
Instance Attribute Details
#config ⇒ Hash (readonly)
18 19 20 |
# File 'lib/kamaze/docker_image/command.rb', line 18 def config @config end |
#parts ⇒ Array<String> (readonly, protected)
58 59 60 |
# File 'lib/kamaze/docker_image/command.rb', line 58 def parts @parts end |
Instance Method Details
#execute ⇒ Boolean
51 52 53 |
# File 'lib/kamaze/docker_image/command.rb', line 51 def execute system(*self.to_a) end |
#run(&block) ⇒ Object Also known as: call
44 45 46 |
# File 'lib/kamaze/docker_image/command.rb', line 44 def run(&block) sh(*self.to_a, &block) end |
#sh(*cmd, &block) ⇒ Object (protected)
73 74 75 76 77 78 |
# File 'lib/kamaze/docker_image/command.rb', line 73 def sh(*cmd, &block) = cmd.last.is_a?(Hash) ? cmd.pop : {} [:verbose] = config[:verbose] unless .key?(:verbose) utils.sh(*cmd.map(&:to_s).push(), &block) end |
#to_a ⇒ Array<String>
35 36 37 |
# File 'lib/kamaze/docker_image/command.rb', line 35 def to_a parts.clone end |
#to_s ⇒ String
40 41 42 |
# File 'lib/kamaze/docker_image/command.rb', line 40 def to_s Shellwords.join(self.to_a) end |
#utils ⇒ Object (protected)
Get utils.
return [Class]
63 64 65 66 67 68 69 70 |
# 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 |