Module: MethodSource
- Extended by:
- CodeHelpers
- Defined in:
- lib/method_source.rb,
lib/method_source/version.rb,
lib/method_source/code_helpers.rb,
lib/method_source/source_location.rb
Defined Under Namespace
Modules: CodeHelpers, MethodExtensions, ReeSourceLocation, SourceLocation Classes: SourceNotFoundError
Constant Summary collapse
- VERSION =
'1.1.0'.freeze
Class Method Summary collapse
-
.clear_cache ⇒ Object
Clear cache.
-
.comment_helper(source_location, name = nil) ⇒ String
Helper method responsible for opening source file and buffering up the comments for a specified method.
-
.extract_code(source_location) ⇒ Object
deprecated
Deprecated.
— use MethodSource::CodeHelpers#expression_at
-
.lines_for(file_name, name = nil) ⇒ Array<String>
Load a memoized copy of the lines in a file.
-
.source_helper(source_location, name = nil) ⇒ String
Helper method responsible for extracting method body.
-
.valid_expression?(str) ⇒ Boolean
deprecated
Deprecated.
— use MethodSource::CodeHelpers#complete_expression?
Methods included from CodeHelpers
comment_describing, complete_expression?, expression_at
Class Method Details
.clear_cache ⇒ Object
Clear cache.
59 60 61 |
# File 'lib/method_source.rb', line 59 def self.clear_cache @lines_for_file = {} end |
.comment_helper(source_location, name = nil) ⇒ String
Helper method responsible for opening source file and buffering up
the comments for a specified method. Defined here to avoid polluting
Method
class.
38 39 40 41 42 43 |
# File 'lib/method_source.rb', line 38 def self.comment_helper(source_location, name=nil) raise SourceNotFoundError, "Could not locate source for #{name}!" unless source_location file, line = *source_location comment_describing(lines_for(file), line) end |
.extract_code(source_location) ⇒ Object
— use MethodSource::CodeHelpers#expression_at
71 72 73 |
# File 'lib/method_source.rb', line 71 def self.extract_code(source_location) source_helper(source_location) end |
.lines_for(file_name, name = nil) ⇒ Array<String>
Load a memoized copy of the lines in a file.
51 52 53 54 55 56 |
# File 'lib/method_source.rb', line 51 def self.lines_for(file_name, name=nil) @lines_for_file ||= {} @lines_for_file[file_name] ||= File.readlines(file_name) rescue Errno::ENOENT => e raise SourceNotFoundError, "Could not load source for #{name}: #{e.}" end |
.source_helper(source_location, name = nil) ⇒ String
Helper method responsible for extracting method body.
Defined here to avoid polluting Method
class.
23 24 25 26 27 28 29 30 |
# File 'lib/method_source.rb', line 23 def self.source_helper(source_location, name=nil) raise SourceNotFoundError, "Could not locate source for #{name}!" unless source_location file, line = *source_location expression_at(lines_for(file), line) rescue SyntaxError => e raise SourceNotFoundError, "Could not parse source for #{name}: #{e.}" end |
.valid_expression?(str) ⇒ Boolean
— use MethodSource::CodeHelpers#complete_expression?
64 65 66 67 68 |
# File 'lib/method_source.rb', line 64 def self.valid_expression?(str) complete_expression?(str) rescue SyntaxError false end |