Class: Hanami::Utils::ClassAttribute::Attributes Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/utils/class_attribute/attributes.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class attributes set

Since:

  • 2.0.0

Instance Method Summary collapse

Constructor Details

#initialize(attributes: Concurrent::Map.new) ⇒ Attributes

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Attributes.

Since:

  • 2.0.0



15
16
17
# File 'lib/hanami/utils/class_attribute/attributes.rb', line 15

def initialize(attributes: Concurrent::Map.new)
  @attributes = attributes
end

Instance Method Details

#[](key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



27
28
29
# File 'lib/hanami/utils/class_attribute/attributes.rb', line 27

def [](key)
  @attributes.fetch(key, nil)
end

#[]=(key, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



21
22
23
# File 'lib/hanami/utils/class_attribute/attributes.rb', line 21

def []=(key, value)
  @attributes[key.to_sym] = value
end

#dupObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



33
34
35
36
37
38
39
40
41
# File 'lib/hanami/utils/class_attribute/attributes.rb', line 33

def dup
  attributes = Concurrent::Map.new.tap do |attrs|
    @attributes.each do |key, value|
      attrs[key.to_sym] = value.dup
    end
  end

  self.class.new(attributes: attributes)
end