Class: SimpleEnumeration::Collections::CustomFactory

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enum_class:, collection_name:, types:) ⇒ CustomFactory

Returns a new instance of CustomFactory.



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

def initialize(enum_class:, collection_name:, types:)
  @enum_class = enum_class
  @collection_name = collection_name
  @types = types
end

Instance Attribute Details

#collection_nameObject (readonly)

Returns the value of attribute collection_name.



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

def collection_name
  @collection_name
end

#enum_classObject (readonly)

Returns the value of attribute enum_class.



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

def enum_class
  @enum_class
end

#typesObject (readonly)

Returns the value of attribute types.



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

def types
  @types
end

Class Method Details

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



14
15
16
# File 'lib/simple_enumeration/collections/custom_factory.rb', line 14

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

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/simple_enumeration/collections/custom_factory.rb', line 18

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

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

  types.each do |type|
    collection.add_type(type.value, type)
  end

  collection
end