module Bauxite::ActionModule

Action common state and behavior.

Attributes

cmd[R]

Parsed action command (i.e. action name)

file[R]

File where the action was defined.

line[R]

Line in the file where the action was defined.

text[R]

Raw action text.

Public Class Methods

new(ctx, cmd, args, text, file, line) click to toggle source

Constructs a new test action instance.

# File lib/bauxite/core/action.rb, line 39
def initialize(ctx, cmd, args, text, file, line)
        @ctx  = ctx
        @cmd  = cmd
        @args = args
        @text = text
        @file = file
        @line = line
        
        @cmd_real = (respond_to? cmd+'_action') ? (cmd+'_action') : cmd
        
        unless respond_to? @cmd_real and Context::actions.include? @cmd
                raise "#{file} (line #{line+1}): Unknown command #{cmd}."
        end
end

Public Instance Methods

args(quote = false) click to toggle source

Returns the action arguments after applying variable expansion.

See Bauxite::Context#expand.

If quote is true, the arguments are surrounded by quote characters (“) and every quote inside an argument is doubled.

For example:

# assuming 
#     action.new(ctx, cmd,
#         [ 'dude', 'say "hi"', '${myvar} ], # args
#         text, file, line)
#     ctx.variables = { 'myvar' => 'world' }

action.args
# => [ 'dude', 'say "hi"', 'world' ]

action.args(true)
# => [ '"dude"', '"say ""hi"""', '"world"' ]
# File lib/bauxite/core/action.rb, line 74
def args(quote = false)
        ret = @args.map { |a| @ctx.expand(a) }
        ret = ret.map { |a| '"'+a.gsub('"', '""')+'"' } if quote
        ret
end
execute() click to toggle source

Executes the action evaluating the arguments in the current context.

Note that execute calls args to expand variables. This means that two calls to execute on the same instance might yield different results.

For example:

action = ctx.parse_action('echo ${message}')

ctx.variables = { 'message' => 'hi!' }
action.execute()
# => outputs 'hi!'

ctx.variables['message'] = 'hello world'
action.execute()
# => outputs 'hello world!' yet the instance of action is same!
# File lib/bauxite/core/action.rb, line 96
def execute()
        send(@cmd_real, *args)
end