Class: DirtySeed::Assigners::Base

Inherits:
Assigner
  • Object
show all
Defined in:
lib/dirty_seed/assigners/base.rb

Overview

Draws a value matching validators

Instance Attribute Summary

Attributes inherited from Assigner

#attribute

Instance Method Summary collapse

Methods inherited from Assigner

#initialize

Constructor Details

This class inherits a constructor from DirtySeed::Assigners::Assigner

Instance Method Details

#value<?>

Returns a value depending on validators and attribute type

It firstly check if value can be set relying to validators
If not, it delegates to an assigner adapted to the attribute type

Returns:

  • (<?>)

    depends on attribute



14
15
16
17
18
19
20
# File 'lib/dirty_seed/assigners/base.rb', line 14

def value
  return if absent?
  return inclusion_options.sample if inclusion_options.is_a? Array
  return rand(inclusion_options) if inclusion_options.is_a? Range

  try_specific || adapted_assigner&.value
end