summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConrad Irwin <conrad.irwin@gmail.com>2013-03-28 01:05:55 -0700
committerConrad Irwin <conrad.irwin@gmail.com>2013-03-28 01:05:55 -0700
commit28d0905eb6c50d1e69d58857e76b0631fe71b39f (patch)
tree5f97a0a44ec4a78a029c7ec4ff87b85a1553e26b
parent29397efb371b34cefbf7c1f1d30b38f59888b49b (diff)
downloadpry-28d0905eb6c50d1e69d58857e76b0631fe71b39f.tar.gz
Move cache reading into Pry::Code for consistency
This necessitates ensuring that the wrapping doesn't add any newlines
-rw-r--r--lib/pry/code.rb2
-rw-r--r--lib/pry/method.rb2
-rw-r--r--lib/pry/method/patcher.rb8
3 files changed, 7 insertions, 5 deletions
diff --git a/lib/pry/code.rb b/lib/pry/code.rb
index c8c9c52d..36cd6c9a 100644
--- a/lib/pry/code.rb
+++ b/lib/pry/code.rb
@@ -61,6 +61,8 @@ class Pry
def from_file(filename, code_type = type_from_filename(filename))
code = if filename == Pry.eval_path
Pry.line_buffer.drop(1)
+ elsif Pry::Method::Patcher.code_for(filename)
+ Pry::Method::Patcher.code_for(filename)
else
File.read(abs_path(filename))
end
diff --git a/lib/pry/method.rb b/lib/pry/method.rb
index acf91e46..40bcda40 100644
--- a/lib/pry/method.rb
+++ b/lib/pry/method.rb
@@ -266,7 +266,7 @@ class Pry
when :c
c_source
when :ruby
- Patcher.new(self).cached_source || ruby_source
+ ruby_source
end
end
diff --git a/lib/pry/method/patcher.rb b/lib/pry/method/patcher.rb
index 07dfa8fb..ef09722e 100644
--- a/lib/pry/method/patcher.rb
+++ b/lib/pry/method/patcher.rb
@@ -9,8 +9,8 @@ class Pry
@method = method
end
- def cached_source
- @@source_cache[method.source_file]
+ def self.code_for(filename)
+ @@source_cache[filename]
end
# perform the patch
@@ -97,7 +97,7 @@ class Pry
def wrap_for_owner(source)
Pry.current[:pry_owner] = method.owner
owner_source = definition_for_owner(source)
- "Pry.current[:pry_owner].class_eval do\n#{owner_source}\nend"
+ "Pry.current[:pry_owner].class_eval do; #{owner_source}\nend"
end
# Update the new source code to have the correct Module.nesting.
@@ -115,7 +115,7 @@ class Pry
def wrap_for_nesting(source)
nesting = Pry::Code.from_file(method.source_file).nesting_at(method.source_line)
- (nesting + [source] + nesting.map{ "end" } + [""]).join("\n")
+ (nesting + [source] + nesting.map{ "end" } + [""]).join(";")
rescue Pry::Indent::UnparseableNestingError
source
end