Class: Prysless::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/prysless.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initializeShell

Returns a new instance of Shell.



90
91
92
93
# File 'lib/prysless.rb', line 90

def initialize
    load_objects
    shell
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *params, &block) ⇒ Object (private)

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



127
128
129
130
131
132
133
134
# 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