Class: CloudMaker::ShellExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud_maker/shell_executor.rb

Constant Summary collapse

YAML_DOMAIN =

If we don’t use yaml.org,2002 some YAML implementations don’t pickup our !shell-script nodes properly.

"yaml.org,2002"
YAML_TYPE =
"shell-script"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script) ⇒ ShellExecutor

Returns a new instance of ShellExecutor.



9
10
11
# File 'lib/cloud_maker/shell_executor.rb', line 9

def initialize(script)
  self.script = script
end

Instance Attribute Details

#scriptObject

Returns the value of attribute script.



7
8
9
# File 'lib/cloud_maker/shell_executor.rb', line 7

def script
  @script
end

Class Method Details

.from_string_representation(string_representation) ⇒ Object



31
32
33
# File 'lib/cloud_maker/shell_executor.rb', line 31

def self.from_string_representation(string_representation)
  ShellExecutor.new(string_representation)
end

Instance Method Details

#executeObject



23
24
25
# File 'lib/cloud_maker/shell_executor.rb', line 23

def execute
  @result ||= `#{self.script}`.strip
end

#to_sObject



27
28
29
# File 'lib/cloud_maker/shell_executor.rb', line 27

def to_s
  execute
end

#to_yaml(opts = {}) ⇒ Object



17
18
19
20
21
# File 'lib/cloud_maker/shell_executor.rb', line 17

def to_yaml(opts = {})
  YAML.quick_emit( nil, opts ) { |out|
    out.scalar( "tag:yaml.org,2002:str", execute, :plain )
  }
end

#to_yaml_typeObject



13
14
15
# File 'lib/cloud_maker/shell_executor.rb', line 13

def to_yaml_type
  "#{YAML_DOMAIN}/#{YAML_TYPE}"
end