Class: MetaCommit::Extension::RubySupport::Models::Ast
- Inherits:
-
Contracts::Ast
- Object
- Contracts::Ast
- MetaCommit::Extension::RubySupport::Models::Ast
- Defined in:
- lib/meta_commit_ruby_support/models/ast.rb
Overview
Adapter which implements MetaCommit::Contracts::Ast contract and wraps Parser::AST::Node
Instance Attribute Summary collapse
-
#ast ⇒ Array<Parser::AST::Node>
The current value of ast.
Instance Method Summary collapse
- #children ⇒ Array<MetaCommit::Contracts::Ast>
- #class_name ⇒ String
- #classes ⇒ Array<Ast>
- #empty_ast? ⇒ Boolean
- #first_line ⇒ Integer
-
#initialize(ast) ⇒ Ast
constructor
A new instance of Ast.
- #is_class? ⇒ Boolean
- #is_method? ⇒ Boolean
- #is_module? ⇒ Boolean
- #last_line ⇒ Integer
- #method_name ⇒ String
- #module_name ⇒ String
- #to_s ⇒ Object
Constructor Details
#initialize(ast) ⇒ Ast
Returns a new instance of Ast.
8 9 10 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 8 def initialize(ast) @ast = ast end |
Instance Attribute Details
#ast ⇒ Array<Parser::AST::Node>
Returns the current value of ast.
4 5 6 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 4 def ast @ast end |
Instance Method Details
#children ⇒ Array<MetaCommit::Contracts::Ast>
13 14 15 16 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 13 def children @ast.children .map {|child| Ast.new(child)} end |
#class_name ⇒ String
64 65 66 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 64 def class_name @ast.children.first.children.last.to_s end |
#classes ⇒ Array<Ast>
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 74 def classes accumulator=[] begin return if empty_ast? return self if is_class? accumulator.concat(children.map {|child| child.classes}) rescue NoMethodError return nil end accumulator.flatten.compact end |
#empty_ast? ⇒ Boolean
39 40 41 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 39 def empty_ast? @ast.nil? end |
#first_line ⇒ Integer
19 20 21 22 23 24 25 26 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 19 def first_line return unless @ast.respond_to?(:location) begin return @ast.location.first_line rescue NoMethodError return nil end end |
#is_class? ⇒ Boolean
49 50 51 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 49 def is_class? @ast.type == :class end |
#is_method? ⇒ Boolean
54 55 56 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 54 def is_method? @ast.type == :def end |
#is_module? ⇒ Boolean
44 45 46 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 44 def is_module? @ast.type == :module end |
#last_line ⇒ Integer
29 30 31 32 33 34 35 36 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 29 def last_line return unless @ast.respond_to?(:location) begin return @ast.location.last_line rescue NoMethodError return nil end end |
#method_name ⇒ String
69 70 71 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 69 def method_name @ast.children.first.to_s end |
#module_name ⇒ String
59 60 61 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 59 def module_name @ast.children.first.children.last.to_s end |
#to_s ⇒ Object
86 87 88 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 86 def to_s @ast.to_s end |