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: []) ⇒ ConstantNode

Returns a new instance of ConstantNode.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/archspec/model.rb', line 36

def initialize(name:, kind:, path:, location:, nesting: [])
  @name = name
  @kind = kind
  @path = path
  @location = location
  @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.



32
33
34
# File 'lib/archspec/model.rb', line 32

def class_methods
  @class_methods
end

#instance_methodsObject (readonly)

Returns the value of attribute instance_methods.



32
33
34
# File 'lib/archspec/model.rb', line 32

def instance_methods
  @instance_methods
end

#kindObject (readonly)

Returns the value of attribute kind.



32
33
34
# File 'lib/archspec/model.rb', line 32

def kind
  @kind
end

#locationObject (readonly)

Returns the value of attribute location.



32
33
34
# File 'lib/archspec/model.rb', line 32

def location
  @location
end

#method_definitionsObject (readonly)

Returns the value of attribute method_definitions.



32
33
34
# File 'lib/archspec/model.rb', line 32

def method_definitions
  @method_definitions
end

#mixinsObject (readonly)

Returns the value of attribute mixins.



32
33
34
# File 'lib/archspec/model.rb', line 32

def mixins
  @mixins
end

#nameObject (readonly)

Returns the value of attribute name.



32
33
34
# File 'lib/archspec/model.rb', line 32

def name
  @name
end

#nestingObject (readonly)

Returns the value of attribute nesting.



32
33
34
# File 'lib/archspec/model.rb', line 32

def nesting
  @nesting
end

#pathObject (readonly)

Returns the value of attribute path.



32
33
34
# File 'lib/archspec/model.rb', line 32

def path
  @path
end

#superclassObject

Returns the value of attribute superclass.



34
35
36
# File 'lib/archspec/model.rb', line 34

def superclass
  @superclass
end

Instance Method Details

#add_class_method(name, location:, visibility: :public) ⇒ Object



65
66
67
68
# File 'lib/archspec/model.rb', line 65

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

#add_instance_method(name, location:, visibility: :public) ⇒ Object



60
61
62
63
# File 'lib/archspec/model.rb', line 60

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

#add_mixin(kind, name) ⇒ Object



70
71
72
# File 'lib/archspec/model.rb', line 70

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

#class?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/archspec/model.rb', line 52

def class?
  kind == :class
end

#module?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/archspec/model.rb', line 56

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.



76
77
78
79
80
81
# File 'lib/archspec/model.rb', line 76

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