Class: Tabry::Machine

Inherits:
Object
  • Object
show all
Defined in:
lib/tabry/machine.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Machine

Returns a new instance of Machine.



21
22
23
24
# File 'lib/tabry/machine.rb', line 21

def initialize(config)
  @config = config
  @state = State.new(mode: :subcommand, subcommand_stack: [], args: [], flags: {}, help: false, dashdash: false)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



12
13
14
# File 'lib/tabry/machine.rb', line 12

def config
  @config
end

#stateObject (readonly)

Returns the value of attribute state.



12
13
14
# File 'lib/tabry/machine.rb', line 12

def state
  @state
end

Class Method Details

.run(config, tokens) ⇒ Object

Returns a state



15
16
17
18
19
# File 'lib/tabry/machine.rb', line 15

def self.run(config, tokens)
  machine = new(config)
  machine.run(tokens)
  machine.state
end

Instance Method Details

#run(tokens) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/tabry/machine.rb', line 26

def run(tokens)
  tokens.each do |token|
    step(token)
    Tabry::Util.debug "AFTER token #{token.inspect}"
    Tabry::Util.debug "STATE: #{state.inspect}"
  end
end