Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/method_extensions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "method_extensions/method/source_with_doc"
require "method_extensions/source_not_found_error"
# We don't require `super` by default since it patches core methods
# require "method_extensions/method/super"
# require "method_extensions/method/super"
15 changes: 7 additions & 8 deletions lib/method_extensions/method/source_with_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module MethodExtensions
module MethodSourceWithDoc
# Returns method source by parsing the file returned by `Method#source_location`.
#
# If method definition cannot be found `ArgumentError` exception is raised
# If method definition cannot be found `MethodExtensions::SourceNotFoundError` exception is raised
# (this includes methods defined by `attr_accessor`, `module_eval` etc.).
#
# Sample IRB session:
Expand Down Expand Up @@ -57,7 +57,7 @@ def doc
# ruby-1.9.2-head > irb_context.inspect_mode = false # turn off inspect mode so that we can view sources
#
# ruby-1.9.2-head > ActiveRecord::Base.method(:find).source_with_doc
# ArgumentError: failed to find method definition around the lines:
# MethodExtensions::SourceNotFoundError: failed to find method definition around the lines:
# delegate :find, :first, :last, :all, :destroy, :destroy_all, :exists?, :delete, :delete_all, :update, :update_all, :to => :scoped
# delegate :find_each, :find_in_batches, :to => :scoped
#
Expand Down Expand Up @@ -124,7 +124,7 @@ def irb_inspect

require "coderay"
require "rdoc/ri/driver"

puts to_s

if source_location
Expand All @@ -140,7 +140,7 @@ def irb_inspect
# 2. probably need to detect other doc types?
# 3. RDoc::Markup::ToAnsi formatter reflows to the 78 chars width which
# looks ugly
#
#
# begin
# formatter = Class.new(RDoc::Markup::ToAnsi) do
# def wrap(text)
Expand All @@ -165,7 +165,7 @@ def irb_inspect
rescue ArgumentError => e
puts e.message
end

nil
end

Expand Down Expand Up @@ -206,8 +206,7 @@ def method_source
if @method_source
@method_source
else
raise ArgumentError.new("failed to find method definition around the lines:\n" <<
definition_lines.join("\n"))
raise SourceNotFoundError.new(definition_lines)
end
end

Expand Down Expand Up @@ -272,4 +271,4 @@ def on_sp(token)
end
end
end
end if ripper_available
end if ripper_available
9 changes: 9 additions & 0 deletions lib/method_extensions/source_not_found_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module MethodExtensions
class SourceNotFoundError < ArgumentError
def initialize(lines)
message = "failed to find method definition around the lines: \n"
message << lines.join("\n")
super message
end
end
end
6 changes: 3 additions & 3 deletions method_extensions.gemspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
lib = File.expand_path('../lib/', __FILE__)
$:.unshift lib unless $:.include?(lib)

Gem::Specification.new do |s|
s.name = "method_extensions"
s.version = "0.0.8"
s.version = "0.0.9"
s.authors = ["Evgeniy Dolzhenko"]
s.email = ["[email protected]"]
s.homepage = "http://github.com/dolzenko/method_extensions"
s.summary = "Method object extensions for better code navigation"
s.files = Dir.glob("lib/**/*") + %w(method_extensions.gemspec)

s.add_dependency "coderay", "0.9.3"
end
end