diff --git a/lib/method_extensions.rb b/lib/method_extensions.rb index da5412c..e6f4d4b 100644 --- a/lib/method_extensions.rb +++ b/lib/method_extensions.rb @@ -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" \ No newline at end of file +# require "method_extensions/method/super" diff --git a/lib/method_extensions/method/source_with_doc.rb b/lib/method_extensions/method/source_with_doc.rb index 555ab7c..304b98b 100644 --- a/lib/method_extensions/method/source_with_doc.rb +++ b/lib/method_extensions/method/source_with_doc.rb @@ -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: @@ -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 # @@ -124,7 +124,7 @@ def irb_inspect require "coderay" require "rdoc/ri/driver" - + puts to_s if source_location @@ -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) @@ -165,7 +165,7 @@ def irb_inspect rescue ArgumentError => e puts e.message end - + nil end @@ -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 @@ -272,4 +271,4 @@ def on_sp(token) end end end -end if ripper_available \ No newline at end of file +end if ripper_available diff --git a/lib/method_extensions/source_not_found_error.rb b/lib/method_extensions/source_not_found_error.rb new file mode 100644 index 0000000..ecf1fbb --- /dev/null +++ b/lib/method_extensions/source_not_found_error.rb @@ -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 diff --git a/method_extensions.gemspec b/method_extensions.gemspec index 7da8326..ffc55aa 100644 --- a/method_extensions.gemspec +++ b/method_extensions.gemspec @@ -1,9 +1,9 @@ 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 = ["dolzenko@gmail.com"] s.homepage = "http://github.com/dolzenko/method_extensions" @@ -11,4 +11,4 @@ Gem::Specification.new do |s| s.files = Dir.glob("lib/**/*") + %w(method_extensions.gemspec) s.add_dependency "coderay", "0.9.3" -end \ No newline at end of file +end