Class: Lino::Model::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/lino/model/command_line.rb

Constant Summary collapse

COMPONENTS =
[
  i[environment_variables],
  i[command],
  i[options after_command],
  i[subcommands],
  i[options after_subcommands],
  i[arguments],
  i[options after_arguments]
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, opts = {}) ⇒ CommandLine

Returns a new instance of CommandLine.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lino/model/command_line.rb', line 24

def initialize(command, opts = {})
  opts = with_defaults(opts)
  @command = command
  @subcommands = Hamster::Vector.new(opts[:subcommands])
  @options = Hamster::Vector.new(opts[:options])
  @arguments = Hamster::Vector.new(opts[:arguments])
  @environment_variables =
    Hamster::Vector.new(opts[:environment_variables])
  @executor = opts[:executor]
  @working_directory = opts[:working_directory]
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



16
17
18
# File 'lib/lino/model/command_line.rb', line 16

def arguments
  @arguments
end

#commandObject (readonly)

Returns the value of attribute command.



16
17
18
# File 'lib/lino/model/command_line.rb', line 16

def command
  @command
end

#environment_variablesObject (readonly)

Returns the value of attribute environment_variables.



16
17
18
# File 'lib/lino/model/command_line.rb', line 16

def environment_variables
  @environment_variables
end

#executorObject (readonly)

Returns the value of attribute executor.



16
17
18
# File 'lib/lino/model/command_line.rb', line 16

def executor
  @executor
end

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/lino/model/command_line.rb', line 16

def options
  @options
end

#subcommandsObject (readonly)

Returns the value of attribute subcommands.



16
17
18
# File 'lib/lino/model/command_line.rb', line 16

def subcommands
  @subcommands
end

#working_directoryObject (readonly)

Returns the value of attribute working_directory.



16
17
18
# File 'lib/lino/model/command_line.rb', line 16

def working_directory
  @working_directory
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



56
57
58
# File 'lib/lino/model/command_line.rb', line 56

def ==(other)
  self.class == other.class && state == other.state
end

#arrayObject Also known as: to_a



44
45
46
# File 'lib/lino/model/command_line.rb', line 44

def array
  format_components(:array, COMPONENTS.drop(1)).flatten
end

#envObject



40
41
42
# File 'lib/lino/model/command_line.rb', line 40

def env
  @environment_variables.to_h(&:array)
end

#execute(opts = {}) ⇒ Object



36
37
38
# File 'lib/lino/model/command_line.rb', line 36

def execute(opts = {})
  @executor.execute(self, opts)
end

#hashObject



62
63
64
# File 'lib/lino/model/command_line.rb', line 62

def hash
  [self.class, state].hash
end

#stringObject Also known as: to_s



50
51
52
# File 'lib/lino/model/command_line.rb', line 50

def string
  format_components(:string, COMPONENTS).join(' ')
end