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
- #type ⇒ Symbol
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 17 18 19 20 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 13 def children begin @ast.children .map {|child| Ast.new(child)} rescue NoMethodError return [] end end |
#class_name ⇒ String
74 75 76 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 74 def class_name @ast.children.first.children.last.to_s end |
#classes ⇒ Array<Ast>
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 84 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
43 44 45 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 43 def empty_ast? @ast.nil? end |
#first_line ⇒ Integer
23 24 25 26 27 28 29 30 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 23 def first_line return unless @ast.respond_to?(:location) begin return @ast.location.first_line rescue NoMethodError return nil end end |
#is_class? ⇒ Boolean
53 54 55 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 53 def is_class? type == :class end |
#is_method? ⇒ Boolean
58 59 60 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 58 def is_method? type == :def end |
#is_module? ⇒ Boolean
48 49 50 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 48 def is_module? type == :module end |
#last_line ⇒ Integer
33 34 35 36 37 38 39 40 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 33 def last_line return unless @ast.respond_to?(:location) begin return @ast.location.last_line rescue NoMethodError return nil end end |
#method_name ⇒ String
79 80 81 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 79 def method_name @ast.children.first.to_s end |
#module_name ⇒ String
69 70 71 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 69 def module_name @ast.children.first.children.last.to_s end |
#to_s ⇒ Object
96 97 98 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 96 def to_s @ast.to_s end |
#type ⇒ Symbol
63 64 65 66 |
# File 'lib/meta_commit_ruby_support/models/ast.rb', line 63 def type return @ast.class.to_s.to_sym unless @ast.respond_to?(:type) @ast.type end |