Class: Transpec::ProcessedSource
- Inherits:
-
Object
- Object
- Transpec::ProcessedSource
- Defined in:
- lib/transpec/processed_source.rb
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#syntax_error ⇒ Object
readonly
Returns the value of attribute syntax_error.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(buffer, ast, path = nil, syntax_error = nil) ⇒ ProcessedSource
constructor
A new instance of ProcessedSource.
- #to_s ⇒ Object
Constructor Details
#initialize(buffer, ast, path = nil, syntax_error = nil) ⇒ ProcessedSource
Returns a new instance of ProcessedSource.
37 38 39 40 41 42 |
# File 'lib/transpec/processed_source.rb', line 37 def initialize(buffer, ast, path = nil, syntax_error = nil) @buffer = buffer @ast = ast @path = path @syntax_error = syntax_error end |
Instance Attribute Details
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
15 16 17 |
# File 'lib/transpec/processed_source.rb', line 15 def ast @ast end |
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
15 16 17 |
# File 'lib/transpec/processed_source.rb', line 15 def buffer @buffer end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
15 16 17 |
# File 'lib/transpec/processed_source.rb', line 15 def path @path end |
#syntax_error ⇒ Object (readonly)
Returns the value of attribute syntax_error.
15 16 17 |
# File 'lib/transpec/processed_source.rb', line 15 def syntax_error @syntax_error end |
Class Method Details
.parse(source, path = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/transpec/processed_source.rb', line 22 def self.parse(source, path = nil) buffer = Parser::Source::Buffer.new(path || '(string)') buffer.source = source builder = AST::Builder.new parser = Parser::CurrentRuby.new(builder) begin ast = parser.parse(buffer) new(buffer, ast, path) rescue Parser::SyntaxError => error new(buffer, nil, path, error) end end |
.parse_file(path) ⇒ Object
17 18 19 20 |
# File 'lib/transpec/processed_source.rb', line 17 def self.parse_file(path) source = File.read(path) parse(source, path) end |
Instance Method Details
#to_s ⇒ Object
44 45 46 |
# File 'lib/transpec/processed_source.rb', line 44 def to_s buffer.source end |