Class: Vop::CommandParam

Inherits:
Object
  • Object
show all
Defined in:
lib/vop/objects/command_param.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ CommandParam

Returns a new instance of CommandParam.


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vop/objects/command_param.rb', line 7

def initialize(name, options = {})
  @name = name

  unless options.is_a? Hash
    raise "[CommandParam] sanity check failed: unexpected options object class #{options.class}, expected Hash"
  end

  # auto-detect boolean parameters
  if options.has_key? :default
    if options[:default] == true || options[:default] == false
      options[:boolean] = true
    end
  end

  defaults = {
    multi: false,
    mandatory: false,
    default_param: false
  }
  @options = defaults.merge(options)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


5
6
7
# File 'lib/vop/objects/command_param.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options


5
6
7
# File 'lib/vop/objects/command_param.rb', line 5

def options
  @options
end

Instance Method Details

#wants_contextObject

some params do not want to prefilled from the context


30
31
32
33
34
35
# File 'lib/vop/objects/command_param.rb', line 30

def wants_context
  !(
    options.has_key?(:use_context) &&
    options[:use_context] == false
   )
end