diff options
author | Reginald Tan <redge.tan@gmail.com> | 2012-06-02 17:34:40 -0400 |
---|---|---|
committer | Reginald Tan <redge.tan@gmail.com> | 2012-06-02 17:34:40 -0400 |
commit | 662d8a90d50fa69e2d2ae49e8f96f009875cbc9e (patch) | |
tree | e20842aa0801ae93a5134887689ccc8f4bcea0c1 /lib | |
parent | 838bdc982b6cea3000ff1e089ebc99d113f64855 (diff) | |
download | method_source-662d8a90d50fa69e2d2ae49e8f96f009875cbc9e.tar.gz |
Added SourceNotFoundError class
Diffstat (limited to 'lib')
-rw-r--r-- | lib/method_source.rb | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/method_source.rb b/lib/method_source.rb index aa2b34a..0353144 100644 --- a/lib/method_source.rb +++ b/lib/method_source.rb @@ -7,6 +7,9 @@ require "#{direc}/method_source/version" require "#{direc}/method_source/source_location" module MethodSource + + class SourceNotFoundError < StandardError; end + # Determine if a string of code is a valid Ruby expression. # @param [String] code The code to validate. # @return [Boolean] Whether or not the code is a valid Ruby expression. @@ -51,8 +54,7 @@ module MethodSource code rescue Errno::ENOENT - # source_location[0] of evaled methods would return (eval) if __FILE__ and __LINE__ is not given. File.readlines "(eval)" would raise ENOENT - nil + raise SourceNotFoundError, "Cannot get source code located at file: #{source_location[0]}" end # @param [Array] source_location The array containing file_name [String], line [Fixnum] @@ -143,9 +145,9 @@ module MethodSource if respond_to?(:source_location) source = MethodSource.source_helper(source_location) - raise "Cannot locate source for this method: #{name}" if !source + raise SourceNotFoundError, "Cannot locate source for this method: #{name}" if !source else - raise "#{self.class}#source not supported by this Ruby version (#{RUBY_VERSION})" + raise SourceNotFoundError, "#{self.class}#source not supported by this Ruby version (#{RUBY_VERSION})" end source @@ -162,9 +164,9 @@ module MethodSource if respond_to?(:source_location) comment = MethodSource.comment_helper(source_location) - raise "Cannot locate source for this method: #{name}" if !comment + raise SourceNotFoundError, "Cannot locate source for this method: #{name}" if !comment else - raise "#{self.class}#comment not supported by this Ruby version (#{RUBY_VERSION})" + raise SourceNotFoundError, "#{self.class}#comment not supported by this Ruby version (#{RUBY_VERSION})" end comment |