Class: Seedie::FieldValues::FakerBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/seedie/field_values/faker_builder.rb

Instance Method Summary collapse

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_constantObject



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