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

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

Overview

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

Defined Under Namespace

Modules: ActiveRecord4And5Compatibility, ActiveRecord4Compatibility

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ActiveRecord4And5Compatibility

#parent, #parents

Methods included from ActiveRecord4Compatibility

#arel_table, #relation_delegate_class

Constructor Details

#initialize(name, module_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,
  module_parent: nil,
  is_a_kind_of_activerecord_base: false,
  claimed_superclass: nil,
  explicit_table_name: nil,
  abstract_class: nil)
  self.name = name
  self.module_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:

  • value

    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:

  • value

    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

#module_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 module_parent
  @module_parent
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

#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



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

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

#==(other) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/ahnnotate/facet/models/module_node.rb', line 119

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:

  • (Boolean)


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

#base_class?Boolean

Named to fit the ModelSchema interface. It was originally implemented in ActiveRecord::Inheritance in Rails 6.0.

Returns:

  • (Boolean)


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

def base_class?
  base_class == self
end

#class_nameObject



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

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

#is_a_kind_of_activerecord_base?Boolean

Returns:

  • (Boolean)


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

#module_parentsObject

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



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

def module_parents
  if module_parent
    [module_parent, *module_parent.module_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



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

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