Class: Baha::ContainerOptions::Cmd

Inherits:
Option
  • Object
show all
Defined in:
lib/baha/container_options/cmd.rb

Direct Known Subclasses

Entrypoint

Constant Summary

Constants inherited from Option

Option::KEYS

Instance Attribute Summary

Attributes inherited from Option

#config_key, #key, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Option

#eql?, #inspect

Constructor Details

#initialize(*args) ⇒ Cmd

Returns a new instance of Cmd.



12
13
14
15
16
17
18
19
20
# File 'lib/baha/container_options/cmd.rb', line 12

def initialize(*args)
  if args.length < 2 then
    @conf = 'Cmd'
    super('Cmd',*args)
  else
    @conf = args[0]
    super(*args)
  end
end

Class Method Details

.split_command(cmd) ⇒ Object



7
8
9
10
# File 'lib/baha/container_options/cmd.rb', line 7

def self.split_command(cmd)
  require 'csv'
  CSV.parse_line(cmd,{:col_sep => ' ', :skip_blanks => true, :quote_char => '"'})
end

Instance Method Details

#apply(config) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/baha/container_options/cmd.rb', line 21

def apply(config)
  if @value.kind_of?(Array)
    config[@conf] = @value
  else
    config[@conf] = Cmd::split_command(@value)
  end
end

#validate!Object



28
29
30
# File 'lib/baha/container_options/cmd.rb', line 28

def validate!
  raise ERROR("should be an array or string") unless @value.kind_of?(Array) or @value.kind_of?(String)
end