class DirtySeed::Assigners::Meaningful

Manages attributes that are meaningful

Public Instance Methods

respond?() click to toggle source

Can meaning be guessed and does faker type match attribute type? @return [Boolean] @note For instance, if there is a faker match but faker return a string

And the attribute type is float then return false
# File lib/dirty_seed/assigners/meaningful.rb, line 21
def respond?
  @respond ||= meaningful_options.present? && meaningful_options[:types].include?(type.to_s)
end
value() click to toggle source

Returns a random meaningful value @return [Object] a “primitive”

# File lib/dirty_seed/assigners/meaningful.rb, line 11
def value
  return unless respond?

  faker_value(meaningful_options.except(:types))
end

Private Instance Methods

meaningful_attributes() click to toggle source

Returns meaningful attributes @return [Hash] @example

{ address: { generator: 'Address', method: 'full_address' } }
# File lib/dirty_seed/assigners/meaningful.rb, line 37
def meaningful_attributes
  ::YAML.safe_load(
    ::File.read(
      DirtySeed::Engine.root.join(
        'lib', 'config', 'meaningful_attributes.yml'
      )
    )
  ).deep_symbolize_keys
end
meaningful_options() click to toggle source

Returns the meaningful options if the attribute name is meaningful @return [Hash, nil]

# File lib/dirty_seed/assigners/meaningful.rb, line 29
def meaningful_options
  @meaningful_options ||= meaningful_attributes[name]
end