Class: SimpleEnumeration::Collections::BasicFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_enumeration/collections/basic_factory.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enum_class:, definitions:) ⇒ BasicFactory

Returns a new instance of BasicFactory.



8
9
10
11
# File 'lib/simple_enumeration/collections/basic_factory.rb', line 8

def initialize(enum_class:, definitions:)
  @enum_class = enum_class
  @definitions = definitions
end

Instance Attribute Details

#definitionsObject (readonly)

Returns the value of attribute definitions.



6
7
8
# File 'lib/simple_enumeration/collections/basic_factory.rb', line 6

def definitions
  @definitions
end

#enum_classObject (readonly)

Returns the value of attribute enum_class.



6
7
8
# File 'lib/simple_enumeration/collections/basic_factory.rb', line 6

def enum_class
  @enum_class
end

Class Method Details

.call(*params, **options, &block) ⇒ Object



13
14
15
# File 'lib/simple_enumeration/collections/basic_factory.rb', line 13

def self.call(*params, **options, &block)
  new(*params, **options).call(&block)
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/simple_enumeration/collections/basic_factory.rb', line 17

def call
  collection = Collection.new(name: :basic)

  CollectionMethodsDefiner.call(enum_class: enum_class, collection: collection)

  definitions.each do |definition|
    type = TypeBuilder.call(definition: definition, enum_class: enum_class)

    TypeMethodsDefiner.call(enum_class: enum_class, collection: collection, type: type)

    collection.add_type(type.value, type)
  end

  collection
end