class DirtySeed::Assigners::Dispatcher

Dispatchs to the adapted assigner

Constants

TYPE_ASSIGNERS

@!method initialize(attribute) @param attribute [DirtySeed::Attribute] @return [DirtySeed::Assigners::Dispatcher]

Public Instance Methods

value() click to toggle source

Returns a value depending on type and validators @return [Object] a “primitive”

# File lib/dirty_seed/assigners/dispatcher.rb, line 16
def value
  return if absence_validator? || !assigner

  array? ? Array.new(3) { assigner.value } : assigner.value
end

Private Instance Methods

absence_validator?() click to toggle source

Returns true if value should be absent Returns [Boolean]

# File lib/dirty_seed/assigners/dispatcher.rb, line 26
def absence_validator?
  validators&.any? do |validator|
    validator.is_a? ActiveRecord::Validations::AbsenceValidator
  end
end
assigner() click to toggle source

Returns an adapted assigner depending on type and validators @return [#value]

# File lib/dirty_seed/assigners/dispatcher.rb, line 34
def assigner
  return inclusion_assigner if inclusion_assigner.respond?
  return meaningful_assigner if meaningful_assigner.respond?

  type_assigner
end
inclusion_assigner() click to toggle source

Returns an assigner managing inclusion validators @return [DirtySeed::Assigners::Inclusion]

# File lib/dirty_seed/assigners/dispatcher.rb, line 43
def inclusion_assigner
  @inclusion_assigner ||= DirtySeed::Assigners::Inclusion.new(__getobj__)
end
meaningful_assigner() click to toggle source

Returns an assigner managing meaningful attributes @return [DirtySeed::Assigners::Meaningful]

# File lib/dirty_seed/assigners/dispatcher.rb, line 49
def meaningful_assigner
  @meaningful_assigner ||= DirtySeed::Assigners::Meaningful.new(__getobj__)
end
type_assigner() click to toggle source

Returns an assigner dedicated to the attribute type @return [#value] @note If attribute type is not currently handled (json, array…), return nil

# File lib/dirty_seed/assigners/dispatcher.rb, line 56
def type_assigner
  @type_assigner ||=
    type.in?(TYPE_ASSIGNERS) &&
    "DirtySeed::Assigners::Type::#{type.to_s.capitalize}".constantize.new(__getobj__)
end