class Kameleon::Command
Attributes
Public Class Methods
Source
# File lib/kameleon/step.rb, line 12 def initialize(yaml_cmd, microstep_name) @string_cmd = YAML.dump(yaml_cmd).gsub("---", "").strip @raw_cmd_id = Digest::SHA1.hexdigest(YAML.dump(yaml_cmd).gsub("---", "").strip) @microstep_name = microstep_name @identifier = nil end
Public Instance Methods
Source
# File lib/kameleon/step.rb, line 89 def gsub!(arg1, arg2) if value.kind_of? Array value.each { |cmd| cmd.gsub!(arg1, arg2) } else @value.gsub!(arg1, arg2) end remaster_string_cmd_from_value! return self end
Source
# File lib/kameleon/step.rb, line 24 def key if @key.nil? object = YAML.unsafe_load(@string_cmd) if object.kind_of? String @key = object else @key = object.keys.first end end @key rescue lines = @string_cmd.split( /\r?\n/ ).map {|l| "> #{l}" } fail RecipeError, "Syntax error for microstep #{@microstep_name}: \n"\ "#{ lines.join "\n"}" end
Source
# File lib/kameleon/step.rb, line 84 def remaster_string_cmd_from_value! self.string_cmd = YAML.dump(to_array).gsub("---", "").strip return self end
Source
# File lib/kameleon/step.rb, line 78 def string_cmd=(str) Kameleon.ui.debug("Set string_cmd to '#{str}' and clear cached value") @string_cmd = str @value = nil end
Source
# File lib/kameleon/step.rb, line 69 def to_array if value.kind_of? Array map = value.map { |val| val.to_array } return { key => map } else return { key => value } end end
Source
# File lib/kameleon/step.rb, line 40 def value if @value.nil? Kameleon.ui.debug("Parsed string = #{@string_cmd}") object = YAML.unsafe_load(@string_cmd) if object.kind_of? Command @value = object elsif object.kind_of? String @value = nil else raise RecipeError unless object.kind_of? Hash raise RecipeError unless object.keys.count == 1 _, val = object.first unless val.kind_of?(Array) val = val.to_s end # Nested commands if val.kind_of? Array val = val.map { |item| Command.new(item, @microstep_name) } end @value = val end end @value rescue fail RecipeError, "Syntax error after variable resolution for microstep #{@microstep_name}, parsed string =\n"\ "#{@string_cmd}\n"\ "Maybe you should remove trailing newline from variable using '>-' or '|-'" end