Class: FactoryBotFactory::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/factory_bot_factory/attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value, options = {}) ⇒ Attribute

Returns a new instance of Attribute.



5
6
7
8
9
# File 'lib/factory_bot_factory/attribute.rb', line 5

def initialize(key, value, options = {})
  @key     = key
  @value   = value
  @options = options
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



3
4
5
# File 'lib/factory_bot_factory/attribute.rb', line 3

def key
  @key
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/factory_bot_factory/attribute.rb', line 3

def options
  @options
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/factory_bot_factory/attribute.rb', line 3

def value
  @value
end

Instance Method Details

#buildObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/factory_bot_factory/attribute.rb', line 11

def build
  options = [key, value, options]

  values = if value.nil? || value == "null"
    FactoryBotFactory.config.nil_converter.call(*options)
  elsif value.is_a?(String) || value.is_a?(Symbol)
    FactoryBotFactory.config.string_converter.call(*options)
  elsif value.is_a?(Numeric)
    FactoryBotFactory.config.numertic_converter.call(*options)
  elsif value.is_a?(Hash) || value.is_a?(Array)
    FactoryBotFactory.config.hash_converter.call(*options)
  else value.is_a?(OpenStruct)
    FactoryBotFactory.config.open_struct_converter.call(*options)
  end
end