Class: SmartCore::Initializer::Attribute::List Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/smart_core/initializer/attribute/list.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.

Since:

  • 0.1.0

Version:

  • 0.10.0

Instance Method Summary collapse

Constructor Details

#initializevoid

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:

  • 0.1.0

Version:

  • 0.10.0



15
16
17
18
# File 'lib/smart_core/initializer/attribute/list.rb', line 15

def initialize
  @attributes = {}
  @lock = SmartCore::Engine::ReadWriteLock.new
end

Instance Method Details

#add(attribute) ⇒ void Also known as: <<

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.

This method returns an undefined value.

Parameters:

Since:

  • 0.1.0

Version:

  • 0.10.0



47
48
49
# File 'lib/smart_core/initializer/attribute/list.rb', line 47

def add(attribute)
  @lock.write_sync { attributes[attribute.name] = attribute }
end

#concat(list) ⇒ void

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.

This method returns an undefined value.

Parameters:

Since:

  • 0.1.0

Version:

  • 0.10.0



58
59
60
61
62
# File 'lib/smart_core/initializer/attribute/list.rb', line 58

def concat(list)
  @lock.write_sync do
    list.each { |attribute| add(attribute.dup) }
  end
end

#count(&block) ⇒ Integer

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.

Parameters:

  • block (Block)

Returns:

  • (Integer)

Since:

  • 0.1.0

Version:

  • 0.10.0



100
101
102
# File 'lib/smart_core/initializer/attribute/list.rb', line 100

def count(&block)
  @lock.read_sync { attributes.values.count(&block) }
end

#each(&block) ⇒ Enumerable

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.

Parameters:

  • block (Block)

Returns:

  • (Enumerable)

Since:

  • 0.1.0

Version:

  • 0.10.0



79
80
81
82
83
# File 'lib/smart_core/initializer/attribute/list.rb', line 79

def each(&block)
  @lock.read_sync do
    block_given? ? attributes.values.each(&block) : attributes.values.each
  end
end

#fetch(attribute_name) ⇒ SmartCore::Initializer::Atribute Also known as: []

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.

Parameters:

  • attribute_name (Symbol)

Returns:

  • (SmartCore::Initializer::Atribute)

Raises:

Since:

  • 0.8.0

Version:

  • 0.10.0



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/smart_core/initializer/attribute/list.rb', line 28

def fetch(attribute_name)
  @lock.read_sync do
    raise(
      ::SmartCore::Initializer::UndefinedAttributeError,
      "Attribute with `#{attribute_name}` name is not defined in your constructor. " \
      "Please, check your attribute definitions inside your class."
    ) unless attributes.key?(attribute_name)

    attributes[attribute_name]
  end
end

#include?(attribute) ⇒ void

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.

This method returns an undefined value.

Parameters:

Since:

  • 0.1.0



69
70
71
# File 'lib/smart_core/initializer/attribute/list.rb', line 69

def include?(attribute)
  @lock.read_sync { attributes.key?(attribute.name) }
end

#sizeInteger

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:

  • (Integer)

Since:

  • 0.1.0

Version:

  • 0.10.0



90
91
92
# File 'lib/smart_core/initializer/attribute/list.rb', line 90

def size
  @lock.read_sync { attributes.size }
end