Class: Resty::Repl

Inherits:
Object
  • Object
show all
Includes:
Pry::Helpers::BaseHelpers, Readline
Defined in:
lib/resty/repl.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resty_options) ⇒ Repl

Returns a new instance of Repl.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/resty/repl.rb', line 10

def initialize(resty_options)
  @options = Resty::Options.new(resty_options)

  Pry.config.prompt = [ proc { "resty> " }, proc { "*>" }]
  Pry.config.history.file = "~/.ruby_resty_history"
  Pry.config.print = proc do |output, value|
    output = Resty::PrettyPrinter.new(options, value).generate
    begin
      output.is_a?(String) ? stagger_output(output) : stagger_output(output.pretty_inspect)
    rescue Exception
      output.puts(output)
    end
  end
end

Instance Attribute Details

#interruptedObject

Returns the value of attribute interrupted.



8
9
10
# File 'lib/resty/repl.rb', line 8

def interrupted
  @interrupted
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/resty/repl.rb', line 8

def options
  @options
end

Class Method Details

.start(resty_options) ⇒ Object



25
26
27
28
29
30
# File 'lib/resty/repl.rb', line 25

def self.start(resty_options)
  new(resty_options).tap do |repl|
    Pry.config.input = repl
    repl.options.pry
  end
end

Instance Method Details

#readline(current_prompt) ⇒ Object



32
33
34
# File 'lib/resty/repl.rb', line 32

def readline(current_prompt)
  Readline.readline(current_prompt)
end