class Analyst::Entities::Entity
Attributes
ast[R]
parent[R]
Public Class Methods
handles_node(type)
click to toggle source
# File lib/analyst/entities/entity.rb, line 10 def self.handles_node(type) Analyst::Processor.register_processor(type, self) end
new(ast, parent)
click to toggle source
# File lib/analyst/entities/entity.rb, line 18 def initialize(ast, parent) @parent = parent @ast = ast end
process(ast, parent)
click to toggle source
# File lib/analyst/entities/entity.rb, line 14 def self.process(ast, parent) new(ast, parent) end
Public Instance Methods
classes()
click to toggle source
# 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()
click to toggle source
# File lib/analyst/entities/entity.rb, line 81 def conditionals @conditionals ||= contents_of_type(Entities::Conditional) end
constant_assignments()
click to toggle source
# File lib/analyst/entities/entity.rb, line 46 def constant_assignments @constant_assignments ||= top_level_constant_assignments + contents.map(&:constant_assignments).flatten end
constants()
click to toggle source
# File lib/analyst/entities/entity.rb, line 42 def constants @constants ||= top_level_constants + contents.map(&:constants).flatten end
file_path()
click to toggle source
# File lib/analyst/entities/entity.rb, line 97 def file_path ast.location.expression.source_buffer.name end
full_name()
click to toggle source
# File lib/analyst/entities/entity.rb, line 109 def full_name throw "Subclass #{self.class.name} must implement #full_name" end
hashes()
click to toggle source
# File lib/analyst/entities/entity.rb, line 89 def hashes @hashes ||= contents_of_type(Entities::Hash) end
inspect()
click to toggle source
# 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()
click to toggle source
# File lib/analyst/entities/entity.rb, line 101 def line_number ast.location.line end
location()
click to toggle source
# File lib/analyst/entities/entity.rb, line 93 def location "#{file_path}:#{line_number}" end
method_calls()
click to toggle source
# File lib/analyst/entities/entity.rb, line 66 def method_calls @method_calls ||= contents_of_type(Entities::MethodCall) end
methods()
click to toggle source
TODO: rethink the different kinds of Methods. there's really only one kind of Method, right?? ref: www.devalot.com/articles/2008/09/ruby-singleton
# File lib/analyst/entities/entity.rb, line 73 def methods return @methods if defined?(@methods) @methods = contents_of_type(Entities::InstanceMethod) @methods << contents_of_type(Entities::ClassMethod) @methods << contents_of_type(Entities::SingletonMethod) @methods.flatten! end
modules()
click to toggle source
# 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()
click to toggle source
# File lib/analyst/entities/entity.rb, line 105 def source ast.location.expression.source end
strings()
click to toggle source
# File lib/analyst/entities/entity.rb, line 31 def strings @strings ||= contents_of_type(Entities::String) end
top_level_classes()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/analyst/entities/entity.rb, line 54 def top_level_constants @top_level_constants ||= contents_of_type(Entities::Constant) end
top_level_modules()
click to toggle source
# File lib/analyst/entities/entity.rb, line 58 def top_level_modules @top_level_modules ||= contents_of_type(Entities::Module) end
variables()
click to toggle source
# File lib/analyst/entities/entity.rb, line 85 def variables @variables ||= contents_of_type(Entities::VariableAssignment) end
Private Instance Methods
actual_contents()
click to toggle source
# File lib/analyst/entities/entity.rb, line 133 def actual_contents @actual_contents ||= process_node(content_node) end
content_node()
click to toggle source
# File lib/analyst/entities/entity.rb, line 137 def content_node ast.children.last end
contents()
click to toggle source
# File lib/analyst/entities/entity.rb, line 125 def contents @contents ||= if actual_contents.is_a? Entities::CodeBlock actual_contents.contents else Array(actual_contents) end end
contents_of_type(klass)
click to toggle source
# File lib/analyst/entities/entity.rb, line 121 def contents_of_type(klass) contents.select { |entity| entity.is_a? klass } end
process_node(node, parent=self)
click to toggle source
# File lib/analyst/entities/entity.rb, line 141 def process_node(node, parent=self) Analyst::Processor.process_node(node, parent) end
process_nodes(nodes, parent=self)
click to toggle source
# File lib/analyst/entities/entity.rb, line 145 def process_nodes(nodes, parent=self) nodes.map { |node| process_node(node, parent) } end