Class: ArchSpec::ConstantNode

Inherits:
Object
  • Object
show all
Defined in:
lib/archspec/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, kind:, path:, location:, nesting: [], namespace_only: false) ⇒ ConstantNode

Returns a new instance of ConstantNode.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/archspec/model.rb', line 76

def initialize(name:, kind:, path:, location:, nesting: [], namespace_only: false)
  @name = name
  @kind = kind
  @path = path
  @location = location
  @namespace_only = namespace_only
  @nesting = Array(nesting).dup.freeze
  @instance_methods = Set.new
  @class_methods = Set.new
  @method_definitions = []
  @mixins = {
    include: Set.new,
    prepend: Set.new,
    extend: Set.new
  }
end

Instance Attribute Details

#class_methodsObject (readonly)

Returns the value of attribute class_methods.



72
73
74
# File 'lib/archspec/model.rb', line 72

def class_methods
  @class_methods
end

#instance_methodsObject (readonly)

Returns the value of attribute instance_methods.



72
73
74
# File 'lib/archspec/model.rb', line 72

def instance_methods
  @instance_methods
end

#kindObject (readonly)

Returns the value of attribute kind.



72
73
74
# File 'lib/archspec/model.rb', line 72

def kind
  @kind
end

#locationObject (readonly)

Returns the value of attribute location.



72
73
74
# File 'lib/archspec/model.rb', line 72

def location
  @location
end

#method_definitionsObject (readonly)

Returns the value of attribute method_definitions.



72
73
74
# File 'lib/archspec/model.rb', line 72

def method_definitions
  @method_definitions
end

#mixinsObject (readonly)

Returns the value of attribute mixins.



72
73
74
# File 'lib/archspec/model.rb', line 72

def mixins
  @mixins
end

#nameObject (readonly)

Returns the value of attribute name.



72
73
74
# File 'lib/archspec/model.rb', line 72

def name
  @name
end

#namespace_onlyObject

Returns the value of attribute namespace_only.



74
75
76
# File 'lib/archspec/model.rb', line 74

def namespace_only
  @namespace_only
end

#nestingObject (readonly)

Returns the value of attribute nesting.



72
73
74
# File 'lib/archspec/model.rb', line 72

def nesting
  @nesting
end

#pathObject (readonly)

Returns the value of attribute path.



72
73
74
# File 'lib/archspec/model.rb', line 72

def path
  @path
end

#superclassObject

Returns the value of attribute superclass.



74
75
76
# File 'lib/archspec/model.rb', line 74

def superclass
  @superclass
end

Instance Method Details

#add_class_method(name, location:, visibility: :public, signatures: [], alias_target: nil) ⇒ Object



108
109
110
111
112
113
# File 'lib/archspec/model.rb', line 108

def add_class_method(name, location:, visibility: :public, signatures: [], alias_target: nil)
  class_methods.add(name.to_sym)
  method_definitions << MethodDefinition.new(
    self.name, name.to_sym, :class, location, visibility, signatures, alias_target
  )
end

#add_instance_method(name, location:, visibility: :public, signatures: [], alias_target: nil) ⇒ Object



101
102
103
104
105
106
# File 'lib/archspec/model.rb', line 101

def add_instance_method(name, location:, visibility: :public, signatures: [], alias_target: nil)
  instance_methods.add(name.to_sym)
  method_definitions << MethodDefinition.new(
    self.name, name.to_sym, :instance, location, visibility, signatures, alias_target
  )
end

#add_mixin(kind, name) ⇒ Object



115
116
117
# File 'lib/archspec/model.rb', line 115

def add_mixin(kind, name)
  mixins.fetch(kind).add(name)
end

#class?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/archspec/model.rb', line 93

def class?
  kind == :class
end

#module?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/archspec/model.rb', line 97

def module?
  kind == :module
end

#set_visibility(name, scope, visibility) ⇒ Object

Rewrites the visibility of already-recorded definitions, for the private :foo, :bar form that names methods defined earlier.



121
122
123
124
125
126
# File 'lib/archspec/model.rb', line 121

def set_visibility(name, scope, visibility)
  name = name.to_sym
  method_definitions.map! do |definition|
    definition.name == name && definition.scope == scope ? definition.with(visibility: visibility) : definition
  end
end