class BitsDealer::REPL

Public Class Methods

new(options={}) click to toggle source
# File lib/bits_dealer/repl.rb, line 28
def initialize(options={})
  @options = options
end

Public Instance Methods

process(command) click to toggle source
# File lib/bits_dealer/repl.rb, line 51
def process(command)
  begin
    result = eval(command)
    prompt.say "=> #{result}\n" if result
  rescue TTY::Reader::InputInterrupt => e
    prompt.warn "\nGot it, lets do something else."
  rescue SyntaxError => e
    @last_error = e
    prompt.warn "Oops, seems to have been some error."
  rescue NameError => e
    @last_error = e
    prompt.warn "Oops, you tried to use a method or variable that doesn't exist."
  rescue ArgumentError => e
    @last_error = e
    prompt.warn "Oops, you tried to use a method without the right parameters."
  rescue => e
    @last_error = e
    prompt.warn "Opps, didnt worked, something bad happened."
  end
end
start() click to toggle source
# File lib/bits_dealer/repl.rb, line 32
def start
  ensure_configuration

  prompt.say "Hello there! ready to rock in bitso."

  while command = Readline.readline("> ")
    case command
    when "help", '?'
      help
    when "exit", "quit"
      break
    else
      process(command)
    end
  end

  prompt.say "Goodbye, I hope you made money!\n"
end

Private Instance Methods

ensure_configuration() click to toggle source
# File lib/bits_dealer/repl.rb, line 90
def ensure_configuration
  if BitsDealer::Config.needs_configuration?
    prompt.error("\nIMPORTANT!!!\nBitsDealer is not configured, to start using it type 'configure'\n")
  else
    prompt.warn("Hey, we found some configuration files")
    password = prompt.mask("Please input your password to load them: ")
    @config = Config.new(password)
    prompt.ok("Configuration loaded.\n")
  end
end
formatter() click to toggle source
# File lib/bits_dealer/repl.rb, line 78
def formatter
  @formatter ||= Pastel.new
end
helper() click to toggle source
# File lib/bits_dealer/repl.rb, line 82
def helper
  @helper ||= BitsDealer::Helper.new(prompt: prompt, formatter: formatter)
end
nothing() click to toggle source
# File lib/bits_dealer/repl.rb, line 86
def nothing
  prompt.say 'Alright!'
end
prompt() click to toggle source
# File lib/bits_dealer/repl.rb, line 74
def prompt
  @prompt ||= ::TTY::Prompt.new(enable_color: true, prefix: '> ', track_history: false)
end