Class: Ahnnotate::Facet::Models::ModuleNode

Inherits:
Object
  • Object
show all
Includes:
ActiveRecord::ModelSchema::ClassMethods
Defined in:
lib/ahnnotate/facet/models/module_node.rb

Overview

ModuleNode is named as such since ‘Class.is_a?(Module) == true`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, parent: nil, is_a_kind_of_activerecord_base: false, claimed_superclass: nil, explicit_table_name: nil, abstract_class: nil) ⇒ ModuleNode

Returns a new instance of ModuleNode.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ahnnotate/facet/models/module_node.rb', line 33

def initialize(name,
  parent: nil,
  is_a_kind_of_activerecord_base: false,
  claimed_superclass: nil,
  explicit_table_name: nil,
  abstract_class: nil)
  self.name = name
  self.parent = parent
  self.is_a_kind_of_activerecord_base = is_a_kind_of_activerecord_base
  self.claimed_superclass = claimed_superclass
  self.explicit_table_name = explicit_table_name
  self.abstract_class = abstract_class
end

Instance Attribute Details

#abstract_class=(value) ⇒ Object (writeonly)

Sets the attribute abstract_class

Parameters:

  • the value to set the attribute abstract_class to.



27
28
29
# File 'lib/ahnnotate/facet/models/module_node.rb', line 27

def abstract_class=(value)
  @abstract_class = value
end

#claimed_superclassObject



64
65
66
# File 'lib/ahnnotate/facet/models/module_node.rb', line 64

def claimed_superclass
  @claimed_superclass.to_s
end

#explicit_table_nameObject

Returns the value of attribute explicit_table_name.



29
30
31
# File 'lib/ahnnotate/facet/models/module_node.rb', line 29

def explicit_table_name
  @explicit_table_name
end

#is_a_kind_of_activerecord_base=(value) ⇒ Object (writeonly)

Sets the attribute is_a_kind_of_activerecord_base

Parameters:

  • the value to set the attribute is_a_kind_of_activerecord_base to.



28
29
30
# File 'lib/ahnnotate/facet/models/module_node.rb', line 28

def is_a_kind_of_activerecord_base=(value)
  @is_a_kind_of_activerecord_base = value
end

#is_active_record_baseObject

Returns the value of attribute is_active_record_base.



30
31
32
# File 'lib/ahnnotate/facet/models/module_node.rb', line 30

def is_active_record_base
  @is_active_record_base
end

#nameObject

Named to fit the ModelSchema interface. This is basically ‘Class#name`



16
17
18
# File 'lib/ahnnotate/facet/models/module_node.rb', line 16

def name
  @name
end

#parentObject

Named to fit the ModelSchema interface. This is the “outer class”



18
19
20
# File 'lib/ahnnotate/facet/models/module_node.rb', line 18

def parent
  @parent
end

#pathObject

Returns the value of attribute path.



31
32
33
# File 'lib/ahnnotate/facet/models/module_node.rb', line 31

def path
  @path
end

#superclassObject

Named to fit the ModelSchema interface. This is the class that the current class inherits from. This is computed, whereas claimed_superclass is what is parsed from the source



22
23
24
# File 'lib/ahnnotate/facet/models/module_node.rb', line 22

def superclass
  @superclass
end

#table_name_prefixObject

Named to fit the ModelSchema interface. This is currently unsupported



24
25
26
# File 'lib/ahnnotate/facet/models/module_node.rb', line 24

def table_name_prefix
  @table_name_prefix
end

Instance Method Details

#<(other) ⇒ Object



109
110
111
# File 'lib/ahnnotate/facet/models/module_node.rb', line 109

def <(other)
  other == ActiveRecord::Base && is_a_kind_of_activerecord_base?
end

#==(other) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/ahnnotate/facet/models/module_node.rb', line 113

def ==(other)
  if is_active_record_base && other == ActiveRecord::Base
    return true
  end

  super
end

#abstract_class?Boolean

Named to fit the ModelSchema interface

Returns:



60
61
62
# File 'lib/ahnnotate/facet/models/module_node.rb', line 60

def abstract_class?
  !!@abstract_class
end

#base_classObject

Named to fit the ModelSchema interface. It was originally implemented in ActiveRecord::Inheritance. I’ve re-implemented it here via the documentation.



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ahnnotate/facet/models/module_node.rb', line 71

def base_class
  if superclass.is_active_record_base
    return self
  end

  if superclass.abstract_class?
    return self
  end

  superclass.base_class
end

#class_nameObject



93
94
95
96
97
98
99
# File 'lib/ahnnotate/facet/models/module_node.rb', line 93

def class_name
  if @name
    "#{parent.class_name}::#{@name}"
  else
    ""
  end
end

#is_a_kind_of_activerecord_base?Boolean

Returns:



55
56
57
# File 'lib/ahnnotate/facet/models/module_node.rb', line 55

def is_a_kind_of_activerecord_base?
  !!@is_a_kind_of_activerecord_base
end

#parentsObject

Named to fit the ModelSchema interface. It was originally implemented in ActiveSupport::Introspection



85
86
87
88
89
90
91
# File 'lib/ahnnotate/facet/models/module_node.rb', line 85

def parents
  if parent
    [parent, *parent.parent]
  else
    []
  end
end

#pluralize_table_namesObject

Named to fit the ModelSchema interface



48
49
50
# File 'lib/ahnnotate/facet/models/module_node.rb', line 48

def pluralize_table_names
  true
end

#table_nameObject



101
102
103
104
105
106
107
# File 'lib/ahnnotate/facet/models/module_node.rb', line 101

def table_name
  if explicit_table_name
    return @explicit_table_name
  end

  super
end

#table_name_suffixObject



52
53
# File 'lib/ahnnotate/facet/models/module_node.rb', line 52

def table_name_suffix
end