Class: Analyst::Entities::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/analyst/entities/entity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast, parent) ⇒ Entity

Returns a new instance of Entity.



8
9
10
11
# File 'lib/analyst/entities/entity.rb', line 8

def initialize(ast, parent)
  @parent = parent
  @ast = ast
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



6
7
8
# File 'lib/analyst/entities/entity.rb', line 6

def parent
  @parent
end

Instance Method Details

#classesObject

TODO: should every Entity have these accessors? maybe they’re mixins… but would that provide any benefit?



19
20
21
22
23
24
25
# File 'lib/analyst/entities/entity.rb', line 19

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

#full_nameObject



39
40
41
# File 'lib/analyst/entities/entity.rb', line 39

def full_name
  throw "Subclass #{self.class.name} must implement #full_name"
end

#handle_send_node(node) ⇒ Object



13
14
15
16
# File 'lib/analyst/entities/entity.rb', line 13

def handle_send_node(node)
  # raise "Subclass must implement handle_send_node"
  # abstract method.  btw, this feels wrong -- send should be an entity too.  but for now, whatevs.
end

#inspectObject



43
44
45
46
47
# File 'lib/analyst/entities/entity.rb', line 43

def inspect
  "\#<#{self.class}:#{object_id} full_name=#{full_name}>"
rescue
  "\#<#{self.class}:#{object_id}>"
end

#method_callsObject



35
36
37
# File 'lib/analyst/entities/entity.rb', line 35

def method_calls
  @method_calls ||= contents_of_type(Entities::MethodCall)
end

#top_level_classesObject



31
32
33
# File 'lib/analyst/entities/entity.rb', line 31

def top_level_classes
  @top_level_classes ||= contents_of_type(Entities::Class)
end

#top_level_modulesObject



27
28
29
# File 'lib/analyst/entities/entity.rb', line 27

def top_level_modules
  @top_level_modules ||= contents_of_type(Entities::Module)
end