class Balmora::Command::SetVariable
Public Instance Methods
init()
click to toggle source
Calls superclass method
Balmora::Command#init
# File lib/balmora/command/set_variable.rb, line 5 def init() super() @variable = option(:variable) @value = option(:value) end
options()
click to toggle source
Calls superclass method
Balmora::Command#options
# File lib/balmora/command/set_variable.rb, line 12 def options() return super().concat([:variable, :value]) end
run()
click to toggle source
# File lib/balmora/command/set_variable.rb, line 26 def run() parts = @variable.split('.').collect() { |part| part.to_sym() } @config.config[:variables] ||= {} parent = parts[0...-1].inject(@config.config[:variables]) { |current, variable| if !current.instance_of?(::Hash) raise Error.new("wrong variable name #{@variable}: target is not hash") end current[variable] ||= {} next current[variable] } parent[parts[-1]] = @value end
verify()
click to toggle source
# File lib/balmora/command/set_variable.rb, line 16 def verify() if @variable.nil?() raise Error.new('"variable" should be defined') end if @value.nil?() raise Error.new('"value" should be defined') end end