Class: Analyst::Entities::Entity
- Inherits:
-
Object
- Object
- Analyst::Entities::Entity
show all
- Defined in:
- lib/analyst/entities/entity.rb
Direct Known Subclasses
Array, Class, ClassMethod, CodeBlock, Conditional, Constant, ConstantAssignment, Hash, InstanceMethod, InterpolatedString, Lvar, MethodCall, Module, Pair, Root, SingletonClass, SingletonMethod, String, Symbol, Unhandled, VariableAssignment
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(ast, parent) ⇒ Entity
Returns a new instance of Entity.
18
19
20
21
|
# File 'lib/analyst/entities/entity.rb', line 18
def initialize(ast, parent)
@parent = parent
@ast = ast
end
|
Instance Attribute Details
#ast ⇒ Object
Returns the value of attribute ast.
8
9
10
|
# File 'lib/analyst/entities/entity.rb', line 8
def ast
@ast
end
|
#parent ⇒ Object
Returns the value of attribute parent.
8
9
10
|
# File 'lib/analyst/entities/entity.rb', line 8
def parent
@parent
end
|
Class Method Details
.handles_node(type) ⇒ Object
.process(ast, parent) ⇒ Object
14
15
16
|
# File 'lib/analyst/entities/entity.rb', line 14
def self.process(ast, parent)
new(ast, parent)
end
|
Instance Method Details
#classes ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/analyst/entities/entity.rb', line 23
def classes
@classes ||= begin
nested_classes = top_level_classes.map(&:classes).flatten
namespaced_classes = top_level_modules.map(&:classes).flatten
top_level_classes + nested_classes + namespaced_classes
end
end
|
#conditionals ⇒ Object
81
82
83
|
# File 'lib/analyst/entities/entity.rb', line 81
def conditionals
@conditionals ||= contents_of_type(Entities::Conditional)
end
|
#constant_assignments ⇒ Object
46
47
48
|
# File 'lib/analyst/entities/entity.rb', line 46
def constant_assignments
@constant_assignments ||= top_level_constant_assignments + contents.map(&:constant_assignments).flatten
end
|
#constants ⇒ Object
42
43
44
|
# File 'lib/analyst/entities/entity.rb', line 42
def constants
@constants ||= top_level_constants + contents.map(&:constants).flatten
end
|
#file_path ⇒ Object
97
98
99
|
# File 'lib/analyst/entities/entity.rb', line 97
def file_path
ast.location.expression.source_buffer.name
end
|
#full_name ⇒ Object
109
110
111
|
# File 'lib/analyst/entities/entity.rb', line 109
def full_name
throw "Subclass #{self.class.name} must implement #full_name"
end
|
#hashes ⇒ Object
89
90
91
|
# File 'lib/analyst/entities/entity.rb', line 89
def hashes
@hashes ||= contents_of_type(Entities::Hash)
end
|
#inspect ⇒ Object
113
114
115
116
117
|
# File 'lib/analyst/entities/entity.rb', line 113
def inspect
"\#<#{self.class} location=#{location} full_name=#{full_name}>"
rescue
"\#<#{self.class} location=#{location}>"
end
|
#line_number ⇒ Object
101
102
103
|
# File 'lib/analyst/entities/entity.rb', line 101
def line_number
ast.location.line
end
|
#location ⇒ Object
93
94
95
|
# File 'lib/analyst/entities/entity.rb', line 93
def location
"#{file_path}:#{line_number}"
end
|
#method_calls ⇒ Object
66
67
68
|
# File 'lib/analyst/entities/entity.rb', line 66
def method_calls
@method_calls ||= contents_of_type(Entities::MethodCall)
end
|
#modules ⇒ Object
35
36
37
38
39
40
|
# File 'lib/analyst/entities/entity.rb', line 35
def modules
@modules ||= begin
nested_modules = top_level_modules.map(&:modules).flatten
top_level_modules + nested_modules
end
end
|
#source ⇒ Object
105
106
107
|
# File 'lib/analyst/entities/entity.rb', line 105
def source
ast.location.expression.source
end
|
#strings ⇒ Object
31
32
33
|
# File 'lib/analyst/entities/entity.rb', line 31
def strings
@strings ||= contents_of_type(Entities::String)
end
|
#top_level_classes ⇒ Object
62
63
64
|
# File 'lib/analyst/entities/entity.rb', line 62
def top_level_classes
@top_level_classes ||= contents_of_type(Entities::Class)
end
|
#top_level_constant_assignments ⇒ Object
50
51
52
|
# File 'lib/analyst/entities/entity.rb', line 50
def top_level_constant_assignments
@top_level_constant_assignments ||= contents_of_type(Entities::ConstantAssignment)
end
|
#top_level_constants ⇒ Object
54
55
56
|
# File 'lib/analyst/entities/entity.rb', line 54
def top_level_constants
@top_level_constants ||= contents_of_type(Entities::Constant)
end
|
#top_level_modules ⇒ Object
58
59
60
|
# File 'lib/analyst/entities/entity.rb', line 58
def top_level_modules
@top_level_modules ||= contents_of_type(Entities::Module)
end
|
#variables ⇒ Object
85
86
87
|
# File 'lib/analyst/entities/entity.rb', line 85
def variables
@variables ||= contents_of_type(Entities::VariableAssignment)
end
|