Class: FluentCommandBuilder::CommandBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent_command_builder/command_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_name, path = nil) ⇒ CommandBuilder



8
9
10
11
12
# File 'lib/fluent_command_builder/command_builder.rb', line 8

def initialize(command_name, path=nil)
  @command_name = command_name
  @path = path
  @args = ''
end

Instance Attribute Details

#command_nameObject

Returns the value of attribute command_name.



6
7
8
# File 'lib/fluent_command_builder/command_builder.rb', line 6

def command_name
  @command_name
end

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/fluent_command_builder/command_builder.rb', line 6

def path
  @path
end

Instance Method Details

#append(value) ⇒ Object



27
28
29
# File 'lib/fluent_command_builder/command_builder.rb', line 27

def append(value)
  @args << value.to_s
end

#append_arg(arg) ⇒ Object



31
32
33
# File 'lib/fluent_command_builder/command_builder.rb', line 31

def append_arg(arg)
  append " #{arg.to_s}"
end

#argsObject



39
40
41
# File 'lib/fluent_command_builder/command_builder.rb', line 39

def args
  @args.strip
end

#format(value, delimiter = ' ', key_value_separator = '=') ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fluent_command_builder/command_builder.rb', line 14

def format(value, delimiter=' ', key_value_separator='=')
  case
    when value.kind_of?(CommandBase)
      value.to_s
    when value.kind_of?(Hash)
      format_hash value, delimiter, key_value_separator
    when value.kind_of?(Array)
      format_array value, delimiter
    else
      quote_if_includes_space value.to_s
  end
end

#to_sObject



35
36
37
# File 'lib/fluent_command_builder/command_builder.rb', line 35

def to_s
  "#{executable} #{args}".strip
end