Skip to content

Commit

Permalink
Move cache reading into Pry::Code for consistency
Browse files Browse the repository at this point in the history
This necessitates ensuring that the wrapping doesn't add any newlines
  • Loading branch information
ConradIrwin committed Mar 28, 2013
1 parent 29397ef commit 28d0905
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/pry/code.rb
Expand Up @@ -61,6 +61,8 @@ class << self
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
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/method.rb
Expand Up @@ -266,7 +266,7 @@ def source
when :c
c_source
when :ruby
Patcher.new(self).cached_source || ruby_source
ruby_source
end
end

Expand Down
8 changes: 4 additions & 4 deletions lib/pry/method/patcher.rb
Expand Up @@ -9,8 +9,8 @@ def initialize(method)
@method = method
end

def cached_source
@@source_cache[method.source_file]
def self.code_for(filename)
@@source_cache[filename]
end

# perform the patch
Expand Down Expand Up @@ -97,7 +97,7 @@ def wrap(source)
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.
Expand All @@ -115,7 +115,7 @@ def wrap_for_owner(source)
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
Expand Down

0 comments on commit 28d0905

Please sign in to comment.