Class: Jets::CLI::Exec::Repl

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Util::Logging
Defined in:
lib/jets/cli/exec/repl.rb,
lib/jets/cli/exec/repl/history.rb

Defined Under Namespace

Classes: History

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Logging

#log

Constructor Details

#initialize(options = {}) ⇒ Repl

Returns a new instance of Repl.



11
12
13
14
15
# File 'lib/jets/cli/exec/repl.rb', line 11

def initialize(options = {})
  @options = options
  @history = History.new(@options) # load for history to work upon start
  trap_signals
end

Instance Attribute Details

#historyObject (readonly)

Returns the value of attribute history.



10
11
12
# File 'lib/jets/cli/exec/repl.rb', line 10

def history
  @history
end

Instance Method Details

#startObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/jets/cli/exec/repl.rb', line 17

def start
  welcome

  loop do
    input = Readline.readline("$ ", true)

    if input.nil? || input.downcase == "exit"
      puts "Exiting..."
      history.save
      break
    elsif input.strip.empty?
      next
    elsif input.strip.start_with? "history"
      num = input.split(" ")[1]
      history.display(num)
      next
    elsif input.strip.start_with? "!"
      execute_from_history(input)
      next
    elsif input.strip == "status"
      display_last_status
      next
    elsif %w[_ result].include?(input.strip)
      display_last_result
      next
    elsif %w[help ?].include?(input.strip)
      display_help
      next
    end

    if history.list.empty? || input != history.list.last
      history.add(input)
    end
    execute_command(input)
  end
end