Class: Seedie::FieldValues::FakerBuilder
- Inherits:
-
Object
- Object
- Seedie::FieldValues::FakerBuilder
- Defined in:
- lib/seedie/field_values/faker_builder.rb
Instance Method Summary collapse
- #build_faker_constant ⇒ Object
-
#initialize(name, column, validations) ⇒ FakerBuilder
constructor
A new instance of FakerBuilder.
Constructor Details
#initialize(name, column, validations) ⇒ FakerBuilder
Returns a new instance of FakerBuilder.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/seedie/field_values/faker_builder.rb', line 6 def initialize(name, column, validations) @name = name @column = column @validations = validations @faker_expression = "{{Faker::" @unique_prefix = "" @class_prefix = "" @method_prefix = "" @options = "" @seedie_config_custom_attributes = Seedie.configuration.custom_attributes end |
Instance Method Details
#build_faker_constant ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/seedie/field_values/faker_builder.rb', line 18 def build_faker_constant return @seedie_config_custom_attributes[@name.to_sym] if @seedie_config_custom_attributes.key?(@name.to_sym) @unique_prefix = "unique." if has_validation?(:uniqueness) add_faker_class_and_method(@column.type) if has_validation?(:inclusion) handle_inclusion_validation else @options += handle_numericality_validation if has_validation?(:numericality) @options += handle_length_validation if has_validation?(:length) end if @faker_expression.is_a?(String) @faker_expression += "#{@class_prefix}#{@unique_prefix}#{@method_prefix}#{@options}" @faker_expression += "}}" if @faker_expression.start_with?("{{") # We may not need }} when random attributes end @faker_expression end |