class Prysless::Shell
Public: Pry shell allowing to use user defined objects, based on two variables:
* PRYSLESS_LIBRARY_PATH: path to load additional libraries, ":"-separated * PRYSLESS_REQUIRE: variable definitions * PRYSLESS_ALIASES: shell command aliases
Examples
ENV['PRYSLESS_REQUIRE'] = "e=ec2l/Ec2l/Client.new:a=pry/[]" Shell.new # will load an ec2l client in variable e and a new array in variable a
Public Class Methods
new()
click to toggle source
# File lib/prysless.rb, line 90 def initialize load_objects shell end
Private Instance Methods
load_objects()
click to toggle source
# File lib/prysless.rb, line 101 def load_objects @a = {} @aliases = {} var('ALIASES') { |a| k, v = a.split('=', 2); @aliases[k] = v } var('LIBRARY_PATH') { |p| $LOAD_PATH << p } var('REQUIRE') do |p| name , value = p.split("=", 2) gem, object = value.split("/", 2) require gem @a[name] = eval(object.gsub("/", "::")) end @a['s'] = Store.new end
method_missing(method, *params, &block)
click to toggle source
Internal: try and find user defined variable named with the method
if its result is nil, super
Examples
h NameError: undefined local variable or method `h' for #<Prysless::Shell:0x000000019f1c20> from .../lib/prysless.rb:45:in `method_missing' a # with PRYSLESS_REQUIRE="a=pry/[]" => []
Return the declared variable from PRYSLESS_REQUIRE or calls super
# File lib/prysless.rb, line 127 def method_missing method, *params, &block meth = method.to_s if @a[meth] then @a[meth] else meth = @aliases[meth] if @aliases[meth] `#{([meth] + params).join " "}`.split("\n") end end
shell()
click to toggle source
# File lib/prysless.rb, line 95 def shell() binding.pry end
var(name) { |p| ... }
click to toggle source
# File lib/prysless.rb, line 96 def var name value = ENV["PRYSLESS_#{name}"] value = if value == nil then [] else value.split(":") end value.each { |p| yield p } end