Class: FactoryBotFactory::Attribute
- Inherits:
-
Object
- Object
- FactoryBotFactory::Attribute
- Defined in:
- lib/factory_bot_factory/attribute.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(key, value, options = {}) ⇒ Attribute
constructor
A new instance of Attribute.
Constructor Details
#initialize(key, value, options = {}) ⇒ Attribute
Returns a new instance of Attribute.
7 8 9 10 11 |
# File 'lib/factory_bot_factory/attribute.rb', line 7 def initialize(key, value, = {}) @key = key @value = value @options = end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/factory_bot_factory/attribute.rb', line 5 def key @key end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/factory_bot_factory/attribute.rb', line 5 def @options end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/factory_bot_factory/attribute.rb', line 5 def value @value end |
Instance Method Details
#build ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/factory_bot_factory/attribute.rb', line 13 def build = [key, value, ] values = if value.nil? || value == "null" FactoryBotFactory.config.nil_converter.call(*) elsif value.is_a?(DateTime) || value.is_a?(Time) FactoryBotFactory.config.date_time_converter.call(*) elsif value.is_a?(Date) FactoryBotFactory.config.date_converter.call(*) elsif value.is_a?(String) || value.is_a?(Symbol) FactoryBotFactory.config.string_converter.call(*) elsif value.is_a?(Numeric) FactoryBotFactory.config.numeric_converter.call(*) elsif value.is_a?(BigDecimal) FactoryBotFactory.config.big_decimal_converter.call(*) elsif value.is_a?(Hash) FactoryBotFactory.config.hash_converter.call(*) elsif value.is_a?(Array) FactoryBotFactory.config.array_converter.call(*) else value.is_a?(OpenStruct) FactoryBotFactory.config.open_struct_converter.call(*) end end |