Class: Prize::App
Class Attribute Summary collapse
-
.options ⇒ Object
Returns the value of attribute options.
-
.redis ⇒ Object
Returns the value of attribute redis.
-
.redis_client ⇒ Object
Returns the value of attribute redis_client.
Instance Method Summary collapse
- #connect_options ⇒ Object
-
#initialize(options) ⇒ App
constructor
A new instance of App.
- #load_initializer! ⇒ Object
- #run! ⇒ Object
- #run_repl! ⇒ Object
- #start_ssh_proxy! ⇒ Object
Constructor Details
#initialize(options) ⇒ App
Returns a new instance of App.
11 12 13 14 15 16 17 18 19 |
# File 'lib/prize/app.rb', line 11 def initialize() require 'active_support/all' @options = load_initializer! @redis = Redis.new() App. = @options App.redis = @redis App.redis_client = @redis.instance_variable_get('@client') end |
Class Attribute Details
.options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/prize/app.rb', line 8 def @options end |
.redis ⇒ Object
Returns the value of attribute redis.
8 9 10 |
# File 'lib/prize/app.rb', line 8 def redis @redis end |
.redis_client ⇒ Object
Returns the value of attribute redis_client.
8 9 10 |
# File 'lib/prize/app.rb', line 8 def redis_client @redis_client end |
Instance Method Details
#connect_options ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/prize/app.rb', line 21 def opts = @options.to_h.slice(:url, :host, :port, :path, :db, :password, :timeout, :connect_timeout, :replica, :cluster) if @options.ssh_host proxy = start_ssh_proxy! opts.merge!(proxy) end opts end |
#load_initializer! ⇒ Object
31 32 33 34 35 |
# File 'lib/prize/app.rb', line 31 def load_initializer! if File.exists?(File.('~/.prizerc')) load(File.('~/.prizerc')) end end |
#run! ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/prize/app.rb', line 54 def run! if @options.code.present? @redis.instance_eval(@options.code) elsif @options.args.present? @options.args.each do |rb| @redis.instance_eval(IO.read(rb)) end elsif STDIN.isatty run_repl! else @redis.instance_eval(STDIN.read) end end |
#start_ssh_proxy! ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/prize/app.rb', line 37 def start_ssh_proxy! ssh_config = { host: @options.ssh_host, forward_host: @options.host || '127.0.0.1', forward_port: @options.port || 6379 } @options.ssh_user.try { |e| ssh_config.merge!(user: e) } @options.ssh_port.try { |e| ssh_config.merge!(port: e) } @options.ssh_password.try { |e| ssh_config.merge!(password: e) } @options.ssh_local_port.try { |e| ssh_config.merge!(local_port: e) } local_ssh_proxy_port = Prize::SSHProxy.connect(ssh_config) { host: '127.0.0.1', port: local_ssh_proxy_port } end |