pry 0.10.3 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +439 -16
- data/LICENSE +1 -1
- data/README.md +362 -302
- data/bin/pry +4 -7
- data/lib/pry/basic_object.rb +10 -0
- data/lib/pry/block_command.rb +22 -0
- data/lib/pry/class_command.rb +194 -0
- data/lib/pry/cli.rb +84 -97
- data/lib/pry/code/code_file.rb +37 -26
- data/lib/pry/code/code_range.rb +7 -5
- data/lib/pry/code/loc.rb +26 -13
- data/lib/pry/code.rb +42 -31
- data/lib/pry/code_object.rb +53 -28
- data/lib/pry/color_printer.rb +46 -35
- data/lib/pry/command.rb +197 -369
- data/lib/pry/command_set.rb +89 -114
- data/lib/pry/command_state.rb +31 -0
- data/lib/pry/commands/amend_line.rb +86 -82
- data/lib/pry/commands/bang.rb +18 -14
- data/lib/pry/commands/bang_pry.rb +15 -11
- data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
- data/lib/pry/commands/cat/exception_formatter.rb +85 -72
- data/lib/pry/commands/cat/file_formatter.rb +56 -46
- data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
- data/lib/pry/commands/cat.rb +62 -54
- data/lib/pry/commands/cd.rb +40 -35
- data/lib/pry/commands/change_inspector.rb +29 -22
- data/lib/pry/commands/change_prompt.rb +48 -23
- data/lib/pry/commands/clear_screen.rb +20 -0
- data/lib/pry/commands/code_collector.rb +148 -131
- data/lib/pry/commands/disable_pry.rb +23 -19
- data/lib/pry/commands/easter_eggs.rb +23 -34
- data/lib/pry/commands/edit/exception_patcher.rb +21 -17
- data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
- data/lib/pry/commands/edit.rb +185 -157
- data/lib/pry/commands/exit.rb +40 -35
- data/lib/pry/commands/exit_all.rb +24 -20
- data/lib/pry/commands/exit_program.rb +20 -16
- data/lib/pry/commands/find_method.rb +168 -162
- data/lib/pry/commands/fix_indent.rb +16 -12
- data/lib/pry/commands/help.rb +140 -133
- data/lib/pry/commands/hist.rb +151 -149
- data/lib/pry/commands/import_set.rb +20 -15
- data/lib/pry/commands/jump_to.rb +25 -21
- data/lib/pry/commands/list_inspectors.rb +35 -28
- data/lib/pry/commands/ls/constants.rb +59 -31
- data/lib/pry/commands/ls/formatter.rb +42 -36
- data/lib/pry/commands/ls/globals.rb +38 -36
- data/lib/pry/commands/ls/grep.rb +17 -15
- data/lib/pry/commands/ls/instance_vars.rb +29 -28
- data/lib/pry/commands/ls/interrogatable.rb +18 -12
- data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
- data/lib/pry/commands/ls/local_names.rb +26 -24
- data/lib/pry/commands/ls/local_vars.rb +38 -30
- data/lib/pry/commands/ls/ls_entity.rb +47 -52
- data/lib/pry/commands/ls/methods.rb +49 -51
- data/lib/pry/commands/ls/methods_helper.rb +46 -42
- data/lib/pry/commands/ls/self_methods.rb +23 -21
- data/lib/pry/commands/ls.rb +124 -103
- data/lib/pry/commands/nesting.rb +21 -17
- data/lib/pry/commands/play.rb +92 -82
- data/lib/pry/commands/pry_backtrace.rb +22 -17
- data/lib/pry/commands/pry_version.rb +15 -11
- data/lib/pry/commands/raise_up.rb +33 -27
- data/lib/pry/commands/reload_code.rb +60 -48
- data/lib/pry/commands/reset.rb +16 -12
- data/lib/pry/commands/ri.rb +57 -42
- data/lib/pry/commands/save_file.rb +45 -43
- data/lib/pry/commands/shell_command.rb +56 -29
- data/lib/pry/commands/shell_mode.rb +22 -18
- data/lib/pry/commands/show_doc.rb +80 -70
- data/lib/pry/commands/show_info.rb +194 -155
- data/lib/pry/commands/show_input.rb +16 -11
- data/lib/pry/commands/show_source.rb +110 -42
- data/lib/pry/commands/stat.rb +35 -31
- data/lib/pry/commands/switch_to.rb +21 -15
- data/lib/pry/commands/toggle_color.rb +20 -16
- data/lib/pry/commands/watch_expression/expression.rb +32 -27
- data/lib/pry/commands/watch_expression.rb +89 -84
- data/lib/pry/commands/whereami.rb +156 -141
- data/lib/pry/commands/wtf.rb +78 -40
- data/lib/pry/config/attributable.rb +22 -0
- data/lib/pry/config/lazy_value.rb +29 -0
- data/lib/pry/config/memoized_value.rb +34 -0
- data/lib/pry/config/value.rb +24 -0
- data/lib/pry/config.rb +310 -20
- data/lib/pry/control_d_handler.rb +28 -0
- data/lib/pry/core_extensions.rb +22 -9
- data/lib/pry/editor.rb +56 -34
- data/lib/pry/env.rb +18 -0
- data/lib/pry/exception_handler.rb +43 -0
- data/lib/pry/exceptions.rb +13 -18
- data/lib/pry/forwardable.rb +27 -0
- data/lib/pry/helpers/base_helpers.rb +20 -62
- data/lib/pry/helpers/command_helpers.rb +52 -62
- data/lib/pry/helpers/documentation_helpers.rb +21 -12
- data/lib/pry/helpers/options_helpers.rb +15 -8
- data/lib/pry/helpers/platform.rb +55 -0
- data/lib/pry/helpers/table.rb +44 -32
- data/lib/pry/helpers/text.rb +96 -85
- data/lib/pry/helpers.rb +3 -0
- data/lib/pry/history.rb +81 -55
- data/lib/pry/hooks.rb +60 -110
- data/lib/pry/indent.rb +74 -68
- data/lib/pry/input_completer.rb +199 -158
- data/lib/pry/input_lock.rb +7 -10
- data/lib/pry/inspector.rb +36 -24
- data/lib/pry/last_exception.rb +45 -45
- data/lib/pry/method/disowned.rb +19 -5
- data/lib/pry/method/patcher.rb +14 -8
- data/lib/pry/method/weird_method_locator.rb +79 -45
- data/lib/pry/method.rb +178 -124
- data/lib/pry/object_path.rb +37 -28
- data/lib/pry/output.rb +102 -16
- data/lib/pry/pager.rb +187 -174
- data/lib/pry/prompt.rb +213 -25
- data/lib/pry/pry_class.rb +119 -98
- data/lib/pry/pry_instance.rb +261 -224
- data/lib/pry/repl.rb +83 -29
- data/lib/pry/repl_file_loader.rb +27 -22
- data/lib/pry/ring.rb +89 -0
- data/lib/pry/slop/LICENSE +20 -0
- data/lib/pry/slop/commands.rb +190 -0
- data/lib/pry/slop/option.rb +210 -0
- data/lib/pry/slop.rb +672 -0
- data/lib/pry/syntax_highlighter.rb +26 -0
- data/lib/pry/system_command_handler.rb +17 -0
- data/lib/pry/testable/evalable.rb +24 -0
- data/lib/pry/testable/mockable.rb +22 -0
- data/lib/pry/testable/pry_tester.rb +88 -0
- data/lib/pry/testable/utility.rb +34 -0
- data/lib/pry/testable/variables.rb +52 -0
- data/lib/pry/testable.rb +68 -0
- data/lib/pry/version.rb +3 -1
- data/lib/pry/warning.rb +20 -0
- data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +35 -32
- data/lib/pry/wrapped_module.rb +68 -63
- data/lib/pry.rb +133 -149
- metadata +58 -69
- data/lib/pry/commands/disabled_commands.rb +0 -2
- data/lib/pry/commands/gem_cd.rb +0 -26
- data/lib/pry/commands/gem_install.rb +0 -32
- data/lib/pry/commands/gem_list.rb +0 -33
- data/lib/pry/commands/gem_open.rb +0 -29
- data/lib/pry/commands/gist.rb +0 -101
- data/lib/pry/commands/install_command.rb +0 -53
- data/lib/pry/commands/list_prompts.rb +0 -35
- data/lib/pry/commands/simple_prompt.rb +0 -22
- data/lib/pry/commands.rb +0 -6
- data/lib/pry/config/behavior.rb +0 -139
- data/lib/pry/config/convenience.rb +0 -25
- data/lib/pry/config/default.rb +0 -161
- data/lib/pry/history_array.rb +0 -121
- data/lib/pry/plugins.rb +0 -103
- data/lib/pry/rbx_path.rb +0 -22
- data/lib/pry/rubygem.rb +0 -82
- data/lib/pry/terminal.rb +0 -79
- data/lib/pry/test/helper.rb +0 -170
data/lib/pry/config/behavior.rb
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
module Pry::Config::Behavior
|
2
|
-
ASSIGNMENT = "=".freeze
|
3
|
-
NODUP = [TrueClass, FalseClass, NilClass, Symbol, Numeric, Module, Proc].freeze
|
4
|
-
INSPECT_REGEXP = /#{Regexp.escape "default=#<"}/
|
5
|
-
|
6
|
-
module Builder
|
7
|
-
def from_hash(hash, default = nil)
|
8
|
-
new(default).tap do |config|
|
9
|
-
config.merge!(hash)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.included(klass)
|
15
|
-
unless defined?(RESERVED_KEYS)
|
16
|
-
const_set :RESERVED_KEYS, instance_methods(false).map(&:to_s).freeze
|
17
|
-
end
|
18
|
-
klass.extend(Builder)
|
19
|
-
end
|
20
|
-
|
21
|
-
def initialize(default = Pry.config)
|
22
|
-
@default = default
|
23
|
-
@lookup = {}
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
# @return [Pry::Config::Behavior]
|
28
|
-
# returns the default used if a matching value for a key isn't found in self
|
29
|
-
#
|
30
|
-
def default
|
31
|
-
@default
|
32
|
-
end
|
33
|
-
|
34
|
-
def [](key)
|
35
|
-
@lookup[key.to_s]
|
36
|
-
end
|
37
|
-
|
38
|
-
def []=(key, value)
|
39
|
-
key = key.to_s
|
40
|
-
if RESERVED_KEYS.include?(key)
|
41
|
-
raise ArgumentError, "few things are reserved by pry, but using '#{key}' as a configuration key is."
|
42
|
-
end
|
43
|
-
@lookup[key] = value
|
44
|
-
end
|
45
|
-
|
46
|
-
def method_missing(name, *args, &block)
|
47
|
-
key = name.to_s
|
48
|
-
if key[-1] == ASSIGNMENT
|
49
|
-
short_key = key[0..-2]
|
50
|
-
self[short_key] = args[0]
|
51
|
-
elsif key?(key)
|
52
|
-
self[key]
|
53
|
-
elsif @default.respond_to?(name)
|
54
|
-
value = @default.public_send(name, *args, &block)
|
55
|
-
# FIXME: refactor Pry::Hook so that it stores config on the config object,
|
56
|
-
# so that we can use the normal strategy.
|
57
|
-
self[key] = value = value.dup if key == 'hooks'
|
58
|
-
value
|
59
|
-
else
|
60
|
-
nil
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def merge!(other)
|
65
|
-
other = try_convert_to_hash(other)
|
66
|
-
raise TypeError, "unable to convert argument into a Hash" unless other
|
67
|
-
other.each do |key, value|
|
68
|
-
self[key] = value
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def ==(other)
|
73
|
-
@lookup == try_convert_to_hash(other)
|
74
|
-
end
|
75
|
-
alias_method :eql?, :==
|
76
|
-
|
77
|
-
def respond_to_missing?(key, include_private=false)
|
78
|
-
key?(key) or @default.respond_to?(key) or super(key, include_private)
|
79
|
-
end
|
80
|
-
|
81
|
-
def key?(key)
|
82
|
-
key = key.to_s
|
83
|
-
@lookup.key?(key)
|
84
|
-
end
|
85
|
-
|
86
|
-
def clear
|
87
|
-
@lookup.clear
|
88
|
-
true
|
89
|
-
end
|
90
|
-
alias_method :refresh, :clear
|
91
|
-
|
92
|
-
def forget(key)
|
93
|
-
@lookup.delete(key.to_s)
|
94
|
-
end
|
95
|
-
|
96
|
-
def keys
|
97
|
-
@lookup.keys
|
98
|
-
end
|
99
|
-
|
100
|
-
def to_hash
|
101
|
-
@lookup.dup
|
102
|
-
end
|
103
|
-
alias_method :to_h, :to_hash
|
104
|
-
|
105
|
-
|
106
|
-
def inspect
|
107
|
-
key_str = keys.map { |key| "'#{key}'" }.join(",")
|
108
|
-
"#<#{_clip_inspect(self)} local_keys=[#{key_str}] default=#{@default.inspect}>"
|
109
|
-
end
|
110
|
-
|
111
|
-
def pretty_print(q)
|
112
|
-
q.text inspect[1..-1].gsub(INSPECT_REGEXP, "default=<")
|
113
|
-
end
|
114
|
-
|
115
|
-
private
|
116
|
-
def _clip_inspect(obj)
|
117
|
-
"#{obj.class}:0x%x" % obj.object_id << 1
|
118
|
-
end
|
119
|
-
|
120
|
-
def _dup(value)
|
121
|
-
if NODUP.any? { |klass| klass === value }
|
122
|
-
value
|
123
|
-
else
|
124
|
-
value.dup
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def try_convert_to_hash(obj)
|
129
|
-
if Hash === obj
|
130
|
-
obj
|
131
|
-
elsif obj.respond_to?(:to_h)
|
132
|
-
obj.to_h
|
133
|
-
elsif obj.respond_to?(:to_hash)
|
134
|
-
obj.to_hash
|
135
|
-
else
|
136
|
-
nil
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Pry::Config::Convenience
|
2
|
-
SHORTCUTS = [
|
3
|
-
:input,
|
4
|
-
:output,
|
5
|
-
:commands,
|
6
|
-
:print,
|
7
|
-
:exception_handler,
|
8
|
-
:hooks,
|
9
|
-
:color,
|
10
|
-
:pager,
|
11
|
-
:editor,
|
12
|
-
:memory_size,
|
13
|
-
:extra_sticky_locals
|
14
|
-
]
|
15
|
-
|
16
|
-
|
17
|
-
def config_shortcut(*names)
|
18
|
-
names.each do |name|
|
19
|
-
reader = name
|
20
|
-
setter = "#{name}="
|
21
|
-
define_method(reader) { config.public_send(name) }
|
22
|
-
define_method(setter) { |value| config.public_send(setter, value) }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/lib/pry/config/default.rb
DELETED
@@ -1,161 +0,0 @@
|
|
1
|
-
class Pry::Config::Default
|
2
|
-
include Pry::Config::Behavior
|
3
|
-
|
4
|
-
default = {
|
5
|
-
input: proc {
|
6
|
-
lazy_readline
|
7
|
-
},
|
8
|
-
output: proc {
|
9
|
-
$stdout
|
10
|
-
},
|
11
|
-
commands: proc {
|
12
|
-
Pry::Commands
|
13
|
-
},
|
14
|
-
prompt_name: proc {
|
15
|
-
Pry::DEFAULT_PROMPT_NAME
|
16
|
-
},
|
17
|
-
prompt: proc {
|
18
|
-
Pry::DEFAULT_PROMPT
|
19
|
-
},
|
20
|
-
prompt_safe_objects: proc {
|
21
|
-
Pry::DEFAULT_PROMPT_SAFE_OBJECTS
|
22
|
-
},
|
23
|
-
print: proc {
|
24
|
-
Pry::DEFAULT_PRINT
|
25
|
-
},
|
26
|
-
quiet: proc {
|
27
|
-
false
|
28
|
-
},
|
29
|
-
exception_handler: proc {
|
30
|
-
Pry::DEFAULT_EXCEPTION_HANDLER
|
31
|
-
},
|
32
|
-
exception_whitelist: proc {
|
33
|
-
Pry::DEFAULT_EXCEPTION_WHITELIST
|
34
|
-
},
|
35
|
-
hooks: proc {
|
36
|
-
Pry::DEFAULT_HOOKS
|
37
|
-
},
|
38
|
-
pager: proc {
|
39
|
-
true
|
40
|
-
},
|
41
|
-
system: proc {
|
42
|
-
Pry::DEFAULT_SYSTEM
|
43
|
-
},
|
44
|
-
color: proc {
|
45
|
-
Pry::Helpers::BaseHelpers.use_ansi_codes?
|
46
|
-
},
|
47
|
-
default_window_size: proc {
|
48
|
-
5
|
49
|
-
},
|
50
|
-
editor: proc {
|
51
|
-
Pry.default_editor_for_platform
|
52
|
-
}, # TODO: Pry::Platform.editor
|
53
|
-
should_load_rc: proc {
|
54
|
-
true
|
55
|
-
},
|
56
|
-
should_load_local_rc: proc {
|
57
|
-
true
|
58
|
-
},
|
59
|
-
should_trap_interrupts: proc {
|
60
|
-
Pry::Helpers::BaseHelpers.jruby?
|
61
|
-
}, # TODO: Pry::Platform.jruby?
|
62
|
-
disable_auto_reload: proc {
|
63
|
-
false
|
64
|
-
},
|
65
|
-
command_prefix: proc {
|
66
|
-
""
|
67
|
-
},
|
68
|
-
auto_indent: proc {
|
69
|
-
Pry::Helpers::BaseHelpers.use_ansi_codes?
|
70
|
-
},
|
71
|
-
correct_indent: proc {
|
72
|
-
true
|
73
|
-
},
|
74
|
-
collision_warning: proc {
|
75
|
-
false
|
76
|
-
},
|
77
|
-
output_prefix: proc {
|
78
|
-
"=> "
|
79
|
-
},
|
80
|
-
requires: proc {
|
81
|
-
[]
|
82
|
-
},
|
83
|
-
should_load_requires: proc {
|
84
|
-
true
|
85
|
-
},
|
86
|
-
should_load_plugins: proc {
|
87
|
-
true
|
88
|
-
},
|
89
|
-
windows_console_warning: proc {
|
90
|
-
true
|
91
|
-
},
|
92
|
-
control_d_handler: proc {
|
93
|
-
Pry::DEFAULT_CONTROL_D_HANDLER
|
94
|
-
},
|
95
|
-
memory_size: proc {
|
96
|
-
100
|
97
|
-
},
|
98
|
-
extra_sticky_locals: proc {
|
99
|
-
{}
|
100
|
-
},
|
101
|
-
command_completions: proc {
|
102
|
-
proc { commands.keys }
|
103
|
-
},
|
104
|
-
file_completions: proc {
|
105
|
-
proc { Dir["."] }
|
106
|
-
},
|
107
|
-
ls: proc {
|
108
|
-
Pry::Config.from_hash(Pry::Command::Ls::DEFAULT_OPTIONS)
|
109
|
-
},
|
110
|
-
completer: proc {
|
111
|
-
require "pry/input_completer"
|
112
|
-
Pry::InputCompleter
|
113
|
-
}
|
114
|
-
}
|
115
|
-
|
116
|
-
def initialize
|
117
|
-
super(nil)
|
118
|
-
configure_gist
|
119
|
-
configure_history
|
120
|
-
end
|
121
|
-
|
122
|
-
default.each do |key, value|
|
123
|
-
define_method(key) do
|
124
|
-
if default[key].equal?(value)
|
125
|
-
default[key] = instance_eval(&value)
|
126
|
-
end
|
127
|
-
default[key]
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
private
|
132
|
-
# TODO:
|
133
|
-
# all of this configure_* stuff is a relic of old code.
|
134
|
-
# we should try move this code to being command-local.
|
135
|
-
def configure_gist
|
136
|
-
self["gist"] = Pry::Config.from_hash(inspecter: proc(&:pretty_inspect))
|
137
|
-
end
|
138
|
-
|
139
|
-
def configure_history
|
140
|
-
self["history"] = Pry::Config.from_hash "should_save" => true,
|
141
|
-
"should_load" => true
|
142
|
-
history.file = File.expand_path("~/.pry_history") rescue nil
|
143
|
-
if history.file.nil?
|
144
|
-
self.should_load_rc = false
|
145
|
-
history.should_save = false
|
146
|
-
history.should_load = false
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def lazy_readline
|
151
|
-
require 'readline'
|
152
|
-
Readline
|
153
|
-
rescue LoadError
|
154
|
-
warn "Sorry, you can't use Pry without Readline or a compatible library."
|
155
|
-
warn "Possible solutions:"
|
156
|
-
warn " * Rebuild Ruby with Readline support using `--with-readline`"
|
157
|
-
warn " * Use the rb-readline gem, which is a pure-Ruby port of Readline"
|
158
|
-
warn " * Use the pry-coolline gem, a pure-ruby alternative to Readline"
|
159
|
-
raise
|
160
|
-
end
|
161
|
-
end
|
data/lib/pry/history_array.rb
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
class Pry
|
2
|
-
# A history array is an array to which you can only add elements. Older
|
3
|
-
# entries are removed progressively, so that the array never contains more than
|
4
|
-
# N elements.
|
5
|
-
#
|
6
|
-
# History arrays are used by Pry to store the output of the last commands.
|
7
|
-
#
|
8
|
-
# @example
|
9
|
-
# ary = Pry::HistoryArray.new 10
|
10
|
-
# ary << 1 << 2 << 3
|
11
|
-
# ary[0] # => 1
|
12
|
-
# ary[1] # => 2
|
13
|
-
# 10.times { |n| ary << n }
|
14
|
-
# ary[0] # => nil
|
15
|
-
# ary[-1] # => 9
|
16
|
-
class HistoryArray
|
17
|
-
include Enumerable
|
18
|
-
|
19
|
-
# @param [Integer] size Maximum amount of objects in the array
|
20
|
-
def initialize(size)
|
21
|
-
@max_size = size
|
22
|
-
|
23
|
-
@hash = {}
|
24
|
-
@count = 0
|
25
|
-
end
|
26
|
-
|
27
|
-
# Pushes an object at the end of the array
|
28
|
-
# @param [Object] value Object to be added
|
29
|
-
def <<(value)
|
30
|
-
@hash[@count] = value
|
31
|
-
|
32
|
-
if @hash.size > max_size
|
33
|
-
@hash.delete(@count - max_size)
|
34
|
-
end
|
35
|
-
|
36
|
-
@count += 1
|
37
|
-
|
38
|
-
self
|
39
|
-
end
|
40
|
-
|
41
|
-
# @overload [](index)
|
42
|
-
# @param [Integer] index Index of the item to access.
|
43
|
-
# @return [Object, nil] Item at that index or nil if it has been removed.
|
44
|
-
# @overload [](index, size)
|
45
|
-
# @param [Integer] index Index of the first item to access.
|
46
|
-
# @param [Integer] size Amount of items to access
|
47
|
-
# @return [Array, nil] The selected items. Nil if index is greater than
|
48
|
-
# the size of the array.
|
49
|
-
# @overload [](range)
|
50
|
-
# @param [Range<Integer>] range Range of indices to access.
|
51
|
-
# @return [Array, nil] The selected items. Nil if index is greater than
|
52
|
-
# the size of the array.
|
53
|
-
def [](index_or_range, size = nil)
|
54
|
-
if index_or_range.is_a? Integer
|
55
|
-
index = convert_index(index_or_range)
|
56
|
-
|
57
|
-
if size
|
58
|
-
end_index = index + size
|
59
|
-
index > @count ? nil : (index...[end_index, @count].min).map do |n|
|
60
|
-
@hash[n]
|
61
|
-
end
|
62
|
-
else
|
63
|
-
@hash[index]
|
64
|
-
end
|
65
|
-
else
|
66
|
-
range = convert_range(index_or_range)
|
67
|
-
range.begin > @count ? nil : range.map { |n| @hash[n] }
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
# @return [Integer] Amount of objects in the array
|
72
|
-
def size
|
73
|
-
@count
|
74
|
-
end
|
75
|
-
alias count size
|
76
|
-
alias length size
|
77
|
-
|
78
|
-
def empty?
|
79
|
-
size == 0
|
80
|
-
end
|
81
|
-
|
82
|
-
def each
|
83
|
-
((@count - size)...@count).each do |n|
|
84
|
-
yield @hash[n]
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def to_a
|
89
|
-
((@count - size)...@count).map { |n| @hash[n] }
|
90
|
-
end
|
91
|
-
|
92
|
-
# Returns [Hash] copy of the internal @hash history
|
93
|
-
def to_h
|
94
|
-
@hash.dup
|
95
|
-
end
|
96
|
-
|
97
|
-
def pop!
|
98
|
-
@hash.delete @count - 1
|
99
|
-
@count -= 1
|
100
|
-
end
|
101
|
-
|
102
|
-
def inspect
|
103
|
-
"#<#{self.class} size=#{size} first=#{@count - size} max_size=#{max_size}>"
|
104
|
-
end
|
105
|
-
|
106
|
-
# @return [Integer] Maximum amount of objects in the array
|
107
|
-
attr_reader :max_size
|
108
|
-
|
109
|
-
private
|
110
|
-
def convert_index(n)
|
111
|
-
n >= 0 ? n : @count + n
|
112
|
-
end
|
113
|
-
|
114
|
-
def convert_range(range)
|
115
|
-
end_index = convert_index(range.end)
|
116
|
-
end_index += 1 unless range.exclude_end?
|
117
|
-
|
118
|
-
Range.new(convert_index(range.begin), [end_index, @count].min, true)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
data/lib/pry/plugins.rb
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
class Pry
|
2
|
-
class PluginManager
|
3
|
-
PRY_PLUGIN_PREFIX = /^pry-/
|
4
|
-
|
5
|
-
# Placeholder when no associated gem found, displays warning
|
6
|
-
class NoPlugin
|
7
|
-
def initialize(name)
|
8
|
-
@name = name
|
9
|
-
end
|
10
|
-
|
11
|
-
def method_missing(*args)
|
12
|
-
warn "Warning: The plugin '#{@name}' was not found! (no gem found)"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class Plugin
|
17
|
-
attr_accessor :name, :gem_name, :enabled, :spec, :active
|
18
|
-
|
19
|
-
def initialize(name, gem_name, spec, enabled)
|
20
|
-
@name, @gem_name, @enabled, @spec = name, gem_name, enabled, spec
|
21
|
-
end
|
22
|
-
|
23
|
-
# Disable a plugin. (prevents plugin from being loaded, cannot
|
24
|
-
# disable an already activated plugin)
|
25
|
-
def disable!
|
26
|
-
self.enabled = false
|
27
|
-
end
|
28
|
-
|
29
|
-
# Enable a plugin. (does not load it immediately but puts on
|
30
|
-
# 'white list' to be loaded)
|
31
|
-
def enable!
|
32
|
-
self.enabled = true
|
33
|
-
end
|
34
|
-
|
35
|
-
# Load the Command line options defined by this plugin (if they exist)
|
36
|
-
def load_cli_options
|
37
|
-
cli_options_file = File.join(spec.full_gem_path, "lib/#{spec.name}/cli.rb")
|
38
|
-
require cli_options_file if File.exist?(cli_options_file)
|
39
|
-
end
|
40
|
-
# Activate the plugin (require the gem - enables/loads the
|
41
|
-
# plugin immediately at point of call, even if plugin is
|
42
|
-
# disabled)
|
43
|
-
# Does not reload plugin if it's already active.
|
44
|
-
def activate!
|
45
|
-
# Create the configuration object for the plugin.
|
46
|
-
Pry.config.send("#{gem_name.gsub('-', '_')}=", Pry::Config.from_hash({}))
|
47
|
-
|
48
|
-
begin
|
49
|
-
require gem_name if !active?
|
50
|
-
rescue LoadError => e
|
51
|
-
warn "Found plugin #{gem_name}, but could not require '#{gem_name}'"
|
52
|
-
warn e
|
53
|
-
rescue => e
|
54
|
-
warn "require '#{gem_name}' # Failed, saying: #{e}"
|
55
|
-
end
|
56
|
-
|
57
|
-
self.active = true
|
58
|
-
self.enabled = true
|
59
|
-
end
|
60
|
-
|
61
|
-
alias active? active
|
62
|
-
alias enabled? enabled
|
63
|
-
end
|
64
|
-
|
65
|
-
def initialize
|
66
|
-
@plugins = []
|
67
|
-
end
|
68
|
-
|
69
|
-
# Find all installed Pry plugins and store them in an internal array.
|
70
|
-
def locate_plugins
|
71
|
-
Gem.refresh
|
72
|
-
(Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')).each do |gem|
|
73
|
-
next if gem.name !~ PRY_PLUGIN_PREFIX
|
74
|
-
plugin_name = gem.name.split('-', 2).last
|
75
|
-
@plugins << Plugin.new(plugin_name, gem.name, gem, true) if !gem_located?(gem.name)
|
76
|
-
end
|
77
|
-
@plugins
|
78
|
-
end
|
79
|
-
|
80
|
-
# @return [Hash] A hash with all plugin names (minus the 'pry-') as
|
81
|
-
# keys and Plugin objects as values.
|
82
|
-
def plugins
|
83
|
-
h = Hash.new { |_, key| NoPlugin.new(key) }
|
84
|
-
@plugins.each do |plugin|
|
85
|
-
h[plugin.name] = plugin
|
86
|
-
end
|
87
|
-
h
|
88
|
-
end
|
89
|
-
|
90
|
-
# Require all enabled plugins, disabled plugins are skipped.
|
91
|
-
def load_plugins
|
92
|
-
@plugins.each do |plugin|
|
93
|
-
plugin.activate! if plugin.enabled?
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
private
|
98
|
-
def gem_located?(gem_name)
|
99
|
-
@plugins.any? { |plugin| plugin.gem_name == gem_name }
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
data/lib/pry/rbx_path.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
class Pry
|
2
|
-
module RbxPath
|
3
|
-
module_function
|
4
|
-
def is_core_path?(path)
|
5
|
-
Pry::Helpers::BaseHelpers.rbx? && (path.start_with?("kernel") || path.start_with?("lib")) && File.exist?(convert_path_to_full(path))
|
6
|
-
end
|
7
|
-
|
8
|
-
def convert_path_to_full(path)
|
9
|
-
if path.start_with?("kernel")
|
10
|
-
File.join File.dirname(Rubinius::KERNEL_PATH), path
|
11
|
-
elsif path.start_with?("lib")
|
12
|
-
File.join File.dirname(Rubinius::LIB_PATH), path
|
13
|
-
else
|
14
|
-
path
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def rvm_ruby?(path)
|
19
|
-
!!(path =~ /\.rvm/)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/lib/pry/rubygem.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
class Pry
|
4
|
-
module Rubygem
|
5
|
-
|
6
|
-
class << self
|
7
|
-
def installed?(name)
|
8
|
-
if Gem::Specification.respond_to?(:find_all_by_name)
|
9
|
-
Gem::Specification.find_all_by_name(name).any?
|
10
|
-
else
|
11
|
-
Gem.source_index.find_name(name).first
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# Get the gem spec object for the given gem name.
|
16
|
-
#
|
17
|
-
# @param [String] name
|
18
|
-
# @return [Gem::Specification]
|
19
|
-
def spec(name)
|
20
|
-
specs = if Gem::Specification.respond_to?(:each)
|
21
|
-
Gem::Specification.find_all_by_name(name)
|
22
|
-
else
|
23
|
-
Gem.source_index.find_name(name)
|
24
|
-
end
|
25
|
-
|
26
|
-
first_spec = specs.sort_by{ |spec| Gem::Version.new(spec.version) }.last
|
27
|
-
|
28
|
-
first_spec or raise CommandError, "Gem `#{name}` not found"
|
29
|
-
end
|
30
|
-
|
31
|
-
# List gems matching a pattern.
|
32
|
-
#
|
33
|
-
# @param [Regexp] pattern
|
34
|
-
# @return [Array<Gem::Specification>]
|
35
|
-
def list(pattern = /.*/)
|
36
|
-
if Gem::Specification.respond_to?(:each)
|
37
|
-
Gem::Specification.select{|spec| spec.name =~ pattern }
|
38
|
-
else
|
39
|
-
Gem.source_index.gems.values.select{|spec| spec.name =~ pattern }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Completion function for gem-cd and gem-open.
|
44
|
-
#
|
45
|
-
# @param [String] so_far what the user's typed so far
|
46
|
-
# @return [Array<String>] completions
|
47
|
-
def complete(so_far)
|
48
|
-
if so_far =~ / ([^ ]*)\z/
|
49
|
-
self.list(%r{\A#{$2}}).map(&:name)
|
50
|
-
else
|
51
|
-
self.list.map(&:name)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# Installs a gem with all its dependencies.
|
56
|
-
#
|
57
|
-
# @param [String] name
|
58
|
-
# @return [void]
|
59
|
-
def install(name)
|
60
|
-
gemrc_opts = Gem.configuration['gem'].split(' ')
|
61
|
-
destination = if gemrc_opts.include?('--user-install')
|
62
|
-
Gem.user_dir
|
63
|
-
elsif File.writable?(Gem.dir)
|
64
|
-
Gem.dir
|
65
|
-
else
|
66
|
-
Gem.user_dir
|
67
|
-
end
|
68
|
-
installer = Gem::DependencyInstaller.new(:install_dir => destination)
|
69
|
-
installer.install(name)
|
70
|
-
rescue Errno::EACCES
|
71
|
-
raise CommandError,
|
72
|
-
"Insufficient permissions to install #{ Pry::Helpers::Text.green(name) }."
|
73
|
-
rescue Gem::GemNotFoundException
|
74
|
-
raise CommandError,
|
75
|
-
"Gem #{ Pry::Helpers::Text.green(name) } not found. Aborting installation."
|
76
|
-
else
|
77
|
-
Gem.refresh
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
end
|