Class: RSpec::Support::Source Private
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Inherits: | Object |
Defined in: | rspec-support/lib/rspec/support/source.rb, rspec-support/lib/rspec/support/source/location.rb, rspec-support/lib/rspec/support/source/node.rb, rspec-support/lib/rspec/support/source/token.rb |
Overview
Represents a Ruby source file and provides access to AST and tokens.
Class Method Summary
- .from_file(path) Internal use only Internal use only
- .new(source_string, path = nil) ⇒ Source constructor Internal use only Internal use only
Instance Attribute Summary
Instance Method Summary
- #ast Internal use only Internal use only
-
#initialize(source_string, path = nil) ⇒ Source
constructor
Internal use only
Internal use only
:nocov:
- #inspect Internal use only Internal use only
- #lines Internal use only Internal use only
- #nodes_by_line_number Internal use only Internal use only
- #tokens Internal use only Internal use only
- #tokens_by_line_number Internal use only Internal use only
Class Method Details
.from_file(path)
This method is for internal use only.
[ GitHub ]
Instance Attribute Details
#path (readonly)
This method is for internal use only.
[ GitHub ]
# File 'rspec-support/lib/rspec/support/source.rb', line 11
attr_reader :source, :path
#source (readonly)
This method is for internal use only.
[ GitHub ]
# File 'rspec-support/lib/rspec/support/source.rb', line 11
attr_reader :source, :path
Instance Method Details
#ast
This method is for internal use only.
[ GitHub ]
#inspect
This method is for internal use only.
[ GitHub ]
# File 'rspec-support/lib/rspec/support/source.rb', line 46
def inspect "#<#{self.class} #{path}>" end
#lines
This method is for internal use only.
[ GitHub ]
# File 'rspec-support/lib/rspec/support/source.rb', line 42
def lines @lines ||= source.split("\n") end
#nodes_by_line_number
This method is for internal use only.
[ GitHub ]
#tokens
This method is for internal use only.
[ GitHub ]
# File 'rspec-support/lib/rspec/support/source.rb', line 63
def tokens @tokens ||= begin require 'ripper' tokens = Ripper.lex(source) Token.tokens_from_ripper_tokens(tokens) end end
#tokens_by_line_number
This method is for internal use only.
[ GitHub ]
# File 'rspec-support/lib/rspec/support/source.rb', line 78
def tokens_by_line_number @tokens_by_line_number ||= begin nodes_by_line_number = tokens.group_by { |token| token.location.line } Hash.new { |hash, key| hash[key] = [] }.merge(nodes_by_line_number) end end