Class: Mixml::Application::ModifyCommand

Inherits:
SelectCommand
  • Object
show all
Defined in:
lib/mixml/application.rb

Overview

Command that selects and modifies nodes

Instance Attribute Summary collapse

Attributes inherited from SelectCommand

#suppress_output

Instance Method Summary collapse

Methods inherited from SelectCommand

#execute

Constructor Details

#initialize(method, args = ARGV) ⇒ ModifyCommand

Initialize a new command

Parameters:

  • method (Symbol)

    Command method

  • args (Array<String>) (defaults to: ARGV)

    Command arguments



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/mixml/application.rb', line 84

def initialize(method, args = ARGV)
    super(method, args)

    @template = nil
    @optional_expression = false

    option '-s', '--string STRING', String, 'String value' do |value|
        raise SystemExit, 'Value already specified. Please use --string or --template only once.' unless @template.nil?
        @template = Mixml::Template::Text.new(value)
    end

    option '-t', '--template STRING', String, 'Template expression value' do |value|
        raise SystemExit, 'Value already specified. Please use --string or --template only once.' unless @template.nil?
        @template = Mixml::Template::Expression.new(value)
    end
end

Instance Attribute Details

#optional_expressionBoolean

Returns Supplying an expression is optional.

Returns:

  • (Boolean)

    Supplying an expression is optional



78
79
80
# File 'lib/mixml/application.rb', line 78

def optional_expression
  @optional_expression
end

Instance Method Details

#before(args, options) ⇒ Object

Check if an expression is set



102
103
104
105
106
# File 'lib/mixml/application.rb', line 102

def before(args, options)
    if not @optional_expression and @template.nil? then
        raise SystemExit, 'Please specify a value with --string or --template.'
    end
end

#parametersObject

Return the template as parameter



109
110
111
# File 'lib/mixml/application.rb', line 109

def parameters
    [@template]
end