pry 0.8.0pre4-java → 0.8.0pre5-java

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -30,13 +30,13 @@ def apply_spec_defaults(s)
30
30
  end
31
31
 
32
32
  task :test do
33
- sh "bacon -k #{direc}/test/test.rb"
33
+ sh "bacon #{direc}/test/test.rb"
34
34
  end
35
35
 
36
36
  desc "run pry"
37
37
  task :pry do
38
38
  require "#{direc}/lib/pry.rb"
39
- Pry.start
39
+ binding.pry
40
40
  end
41
41
 
42
42
  desc "show pry version"
@@ -68,19 +68,26 @@ class Pry
68
68
  end
69
69
 
70
70
  # Execute a command (this enables commands to call other commands).
71
+ # @param [Binding] target The current target object.
71
72
  # @param [String] name The command to execute
72
73
  # @param [Array] args The parameters to pass to the command.
73
74
  # @example Wrap one command with another
74
75
  # class MyCommands < Pry::Commands
75
76
  # command "ls2" do
76
77
  # output.puts "before ls"
77
- # run "ls"
78
+ # run target, "ls"
78
79
  # output.puts "after ls"
79
80
  # end
80
81
  # end
81
- def run(name, *args)
82
- action = opts[:commands][name][:action]
83
- instance_exec(*args, &action)
82
+ def run(target, name, *args)
83
+ command_processor = CommandProcessor.new(target.eval('_pry_'))
84
+
85
+ if command_processor.system_command?(name)
86
+ command_processor.execute_system_command("#{name} #{args.join}", target)
87
+ else
88
+ action = opts[:commands][name][:action]
89
+ instance_exec(*args, &action)
90
+ end
84
91
  end
85
92
 
86
93
  # Import commands from another command object.
@@ -7,7 +7,7 @@ class Pry
7
7
 
8
8
  extend Forwardable
9
9
 
10
- attr_reader :pry_instance
10
+ attr_accessor :pry_instance
11
11
 
12
12
  def initialize(pry_instance)
13
13
  @pry_instance = pry_instance
@@ -26,10 +26,16 @@ class Pry
26
26
  def pry_command?(val)
27
27
  !!command_matched(val).first
28
28
  end
29
+
30
+ def interpolate_string(str, target)
31
+ dumped_str = str.dump
32
+ dumped_str.gsub!(/\\\#\{/, '#{')
33
+ target.eval(dumped_str)
34
+ end
29
35
 
30
- def execute_system_command(val)
36
+ def execute_system_command(val, target)
31
37
  SYSTEM_COMMAND_REGEX =~ val
32
- cmd = $1
38
+ cmd = interpolate_string($1, target)
33
39
 
34
40
  if cmd =~ /^cd\s+(.+)/i
35
41
  begin
@@ -71,15 +77,16 @@ class Pry
71
77
  def eval_string.clear() replace("") end
72
78
 
73
79
  if system_command?(val)
74
- execute_system_command(val)
80
+ execute_system_command(val, target)
75
81
  return
76
82
  end
77
83
 
84
+ # no command was matched, so return to caller
85
+ return if !pry_command?(val)
86
+
87
+ val.replace interpolate_string(val, target)
78
88
  cmd_data, args_string = command_matched(val)
79
89
 
80
- # no command was matched, so return to caller
81
- return if !cmd_data
82
-
83
90
  args = args_string ? Shellwords.shellwords(args_string) : []
84
91
  action = cmd_data[:action]
85
92
  keep_retval = cmd_data[:keep_retval]
@@ -31,6 +31,16 @@ class Pry
31
31
  end
32
32
  end
33
33
 
34
+ set_file_and_dir_locals = lambda do |file_name|
35
+ return if !target
36
+ FILE_TEMP = File.expand_path(file_name)
37
+ DIR_TEMP = File.dirname(FILE_TEMP)
38
+ target.eval("_file_ = Pry::Commands::FILE_TEMP")
39
+ target.eval("_dir_ = Pry::Commands::DIR_TEMP")
40
+ remove_const(:FILE_TEMP)
41
+ remove_const(:DIR_TEMP)
42
+ end
43
+
34
44
  check_for_dynamically_defined_method = lambda do |meth|
35
45
  file, _ = meth.source_location
36
46
  if file =~ /(\(.*\))|<.*>/
@@ -123,7 +133,7 @@ class Pry
123
133
  command "gem-cd", "Change working directory to specified gem's directory." do |gem_name|
124
134
  require 'rubygems'
125
135
  gem_spec = Gem.source_index.find_name(gem_name).first
126
- next output.put("Gem `#{gem_name}` not found.") if !gem_spec
136
+ next output.puts("Gem `#{gem_name}` not found.") if !gem_spec
127
137
  Dir.chdir(File.expand_path(gem_spec.full_gem_path))
128
138
  end
129
139
 
@@ -149,6 +159,8 @@ class Pry
149
159
  else
150
160
  Pry.active_instance.prompt = Pry::FILE_PROMPT
151
161
  Pry.active_instance.custom_completions = Pry::FILE_COMPLETIONS
162
+ Readline.completion_proc = Pry::InputCompleter.build_completion_proc target,
163
+ Pry.active_instance.instance_eval(&Pry::FILE_COMPLETIONS)
152
164
  end
153
165
  end
154
166
 
@@ -201,6 +213,8 @@ class Pry
201
213
  next
202
214
  end
203
215
 
216
+ set_file_and_dir_locals.call(file)
217
+ puts "blah blah #{target}"
204
218
  output.puts "--\nFrom #{file} @ line #{line_num} in #{klass}##{meth_name}:\n--"
205
219
 
206
220
  # This method inspired by http://rubygems.org/gems/ir_b
@@ -426,20 +440,13 @@ Shows local and instance variables by default.
426
440
  CodeRay.scan(contents, language_detected).term
427
441
  end
428
442
 
429
- read_between_the_lines = lambda do |file_name, start_line, end_line, with_line_numbers|
443
+ read_between_the_lines = lambda do |file_name, start_line, end_line|
430
444
  content = File.read(File.expand_path(file_name))
431
-
432
- if with_line_numbers
433
- lines = content.each_line.map.with_index { |line, idx| "#{idx + 1}: #{line}" }
434
- else
435
- lines = content.each_line.to_a
436
- end
437
-
438
- lines[start_line..end_line].join
445
+ content.each_line.to_a[start_line..end_line].join
439
446
  end
440
447
 
441
448
  add_line_numbers = lambda do |lines, start_line|
442
- lines.each_line.map.with_index do |line, idx|
449
+ lines.each_line.each_with_index.map do |line, idx|
443
450
  adjusted_index = idx + start_line
444
451
  if Pry.color
445
452
  cindex = CodeRay.scan("#{adjusted_index}", :ruby).term
@@ -475,7 +482,7 @@ e.g: cat-file hello.rb
475
482
  end_line = line.to_i - 1
476
483
  end
477
484
 
478
- opts.on("-t", "--type TYPE", "The specific file type for syntax higlighting.") do |type|
485
+ opts.on("-t", "--type TYPE", "The specific file type for syntax higlighting (e.g ruby, python, cpp, java)") do |type|
479
486
  file_type = type.to_sym
480
487
  end
481
488
 
@@ -494,7 +501,7 @@ e.g: cat-file hello.rb
494
501
  next
495
502
  end
496
503
 
497
- contents = read_between_the_lines.call(file_name, start_line, end_line, false)
504
+ contents = read_between_the_lines.call(file_name, start_line, end_line)
498
505
 
499
506
  if Pry.color
500
507
  contents = syntax_highlight_by_file_type_or_specified.call(contents, file_name, file_type)
@@ -503,7 +510,8 @@ e.g: cat-file hello.rb
503
510
  if options[:l]
504
511
  contents = add_line_numbers.call(contents, start_line + 1)
505
512
  end
506
-
513
+
514
+ set_file_and_dir_locals.call(file_name)
507
515
  output.puts contents
508
516
  contents
509
517
  end
@@ -548,6 +556,8 @@ e.g: eval-file -c self "hello.rb"
548
556
  TOPLEVEL_BINDING.eval(File.read(File.expand_path(file_name)))
549
557
  output.puts "--\nEval'd '#{file_name}' at top-level."
550
558
  end
559
+ set_file_and_dir_locals.call(file_name)
560
+
551
561
  new_constants = Object.constants - old_constants
552
562
  output.puts "Brought in the following top-level constants: #{new_constants.inspect}" if !new_constants.empty?
553
563
  end
@@ -680,6 +690,7 @@ e.g show-doc hello_method
680
690
  when :ruby
681
691
  doc = meth.comment
682
692
  doc = strip_leading_hash_and_whitespace_from_ruby_comments.call(doc)
693
+ set_file_and_dir_locals.call(meth.source_location.first)
683
694
  end
684
695
 
685
696
  next output.puts("No documentation found.") if doc.empty?
@@ -749,6 +760,7 @@ e.g: show-method hello_method
749
760
  code = strip_comments_from_c_code.call(code)
750
761
  when :ruby
751
762
  code = strip_leading_whitespace.call(meth.source)
763
+ set_file_and_dir_locals.call(meth.source_location.first)
752
764
  end
753
765
 
754
766
  output.puts make_header.call(meth, code_type)
@@ -778,6 +790,7 @@ e.g: show-method hello_method
778
790
 
779
791
  code = strip_leading_whitespace.call(meth.source)
780
792
  file, line = meth.source_location
793
+ set_file_and_dir_locals.call(file)
781
794
  check_for_dynamically_defined_method.call(meth)
782
795
 
783
796
  output.puts "--\nFrom #{file} @ line #{line}:\n--"
@@ -4,7 +4,7 @@ class Pry
4
4
  DEFAULT_HOOKS = {
5
5
 
6
6
  :before_session => proc do |out, target|
7
- out.puts "Beginning Pry session for #{Pry.view_clip(target.eval('self'))}"
7
+ # out.puts "Beginning Pry session for #{Pry.view_clip(target.eval('self'))}"
8
8
 
9
9
  # ensure we're actually in a method
10
10
  meth_name = target.eval('__method__')
@@ -16,6 +16,6 @@ class Pry
16
16
  end
17
17
  end,
18
18
 
19
- :after_session => proc { |out, target| out.puts "Ending Pry session for #{Pry.view_clip(target.eval('self'))}" }
19
+ # :after_session => proc { |out, target| out.puts "Ending Pry session for #{Pry.view_clip(target.eval('self'))}" }
20
20
  }
21
21
  end
@@ -142,6 +142,7 @@ class Pry
142
142
  def rep(target=TOPLEVEL_BINDING)
143
143
  target = Pry.binding_for(target)
144
144
  result = re(target)
145
+
145
146
  print.call output, result if !@suppress_output
146
147
  end
147
148
 
@@ -235,7 +236,7 @@ class Pry
235
236
  # @param [String] eval_string The cumulative lines of input.
236
237
  # @target [Binding] target The target of the Pry session.
237
238
  def process_line(val, eval_string, target)
238
- val.chomp!
239
+ val.rstrip!
239
240
  Pry.cmd_ret_value = @command_processor.process_commands(val, eval_string, target)
240
241
 
241
242
  if Pry.cmd_ret_value
@@ -1,3 +1,3 @@
1
1
  class Pry
2
- VERSION = "0.8.0pre4"
2
+ VERSION = "0.8.0pre5"
3
3
  end
@@ -70,15 +70,17 @@ describe Pry do
70
70
  o.instance_variable_get(:@x).should == 10
71
71
  end
72
72
 
73
- it 'should execute start session and end session hooks' do
74
- input = InputTester.new("exit")
75
- str_output = StringIO.new
76
- o = Object.new
73
+ # # this is now deprecated
74
+ # it 'should execute start session and end session hooks' do
75
+ # next
76
+ # input = InputTester.new("exit")
77
+ # str_output = StringIO.new
78
+ # o = Object.new
77
79
 
78
- pry_tester = Pry.start(o, :input => input, :output => str_output)
79
- str_output.string.should =~ /Beginning.*#{o}/
80
- str_output.string.should =~ /Ending.*#{o}/
81
- end
80
+ # pry_tester = Pry.start(o, :input => input, :output => str_output)
81
+ # str_output.string.should =~ /Beginning.*#{o}/
82
+ # str_output.string.should =~ /Ending.*#{o}/
83
+ # end
82
84
  end
83
85
 
84
86
  describe "test loading rc files" do
@@ -490,7 +492,7 @@ describe Pry do
490
492
  end
491
493
 
492
494
  command "run_v" do
493
- run "v"
495
+ run target, "v"
494
496
  end
495
497
  end
496
498
 
@@ -514,23 +516,26 @@ describe Pry do
514
516
  str_output = StringIO.new
515
517
  Pry.new(:print => proc {}, :input => InputTester.new("v"),
516
518
  :output => str_output, :commands => Command4).rep("john")
517
- str_output.string.chomp.should == "john"
519
+
520
+ str_output.string.rstrip.should == "john"
518
521
 
519
522
  Object.remove_const(:Command3)
520
523
  Object.remove_const(:Command4)
521
524
  end
522
525
 
523
526
  it 'should import commands from another command object' do
524
- class Command3 < Pry::CommandBase
527
+ Object.remove_const(:Command77) if Object.const_defined?(:Command77)
528
+
529
+ class Command77 < Pry::CommandBase
525
530
  import_from Pry::Commands, "status", "jump-to"
526
531
  end
527
532
 
528
533
  str_output = StringIO.new
529
534
  Pry.new(:print => proc {}, :input => InputTester.new("status"),
530
- :output => str_output, :commands => Command3).rep("john")
535
+ :output => str_output, :commands => Command77).rep("john")
531
536
  str_output.string.should =~ /Status:/
532
537
 
533
- Object.remove_const(:Command3)
538
+ Object.remove_const(:Command77)
534
539
  end
535
540
 
536
541
  it 'should delete some inherited commands when using delete method' do
@@ -569,11 +574,11 @@ describe Pry do
569
574
 
570
575
  str_output = StringIO.new
571
576
  Pry.new(:input => InputTester.new("jump-to"), :output => str_output, :commands => Command3).rep
572
- str_output.string.chomp.should == "jump-to the music"
577
+ str_output.string.rstrip.should == "jump-to the music"
573
578
 
574
579
  str_output = StringIO.new
575
580
  Pry.new(:input => InputTester.new("help"), :output => str_output, :commands => Command3).rep
576
- str_output.string.chomp.should == "help to the music"
581
+ str_output.string.rstrip.should == "help to the music"
577
582
 
578
583
  Object.remove_const(:Command3)
579
584
 
@@ -35,6 +35,7 @@ class Pry
35
35
  # null output class - doesn't write anywwhere.
36
36
  class NullOutput
37
37
  def self.puts(*) end
38
+ def self.string(*) end
38
39
  end
39
40
  end
40
41
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 8
8
- - 0pre4
9
- version: 0.8.0pre4
8
+ - 0pre5
9
+ version: 0.8.0pre5
10
10
  platform: java
11
11
  authors:
12
12
  - John Mair (banisterfiend)