Class: Prize::Repl

Inherits:
Object show all
Defined in:
lib/prize/repl.rb

Instance Method Summary collapse

Constructor Details

#initializeRepl

Returns a new instance of Repl.



8
9
10
11
12
# File 'lib/prize/repl.rb', line 8

def initialize
  @redis = App.redis
  Pry.config.prompt = Pry::Prompt.new("", "", prompt)
  Pry.start(@redis)
end

Instance Method Details

#promptObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/prize/repl.rb', line 14

def prompt
  opts = @redis.instance_variable_get('@client').options
  if App.options.ssh_host
    host = "#{App.options.ssh_host}:#{App.options.host || '127.0.0.1'}:#{App.options.port || 6379}/#{opts[:db]}"
  else
    host = opts[:url] || opts[:path] || "#{opts[:host]}:#{opts[:port]}/#{opts[:db]}"
  end
  [proc do |obj, nest_level, _|
     if obj == @redis && nest_level == 0
       nest_level_prompt = ''
     else
       nest_level_prompt = "(#{obj}:#{nest_level})"
     end
     "%s#{Rainbow('@').green}%s#{nest_level_prompt} %s " % [Rainbow('PRIZE').red, Rainbow(host).yellow, Rainbow('').green]
   end]
end