Class: RandomizedField::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/randomized_field/callback.rb

Overview

Implements the before_create ActiveRecord callback used to set the value of the randomized field.

Instance Method Summary collapse

Constructor Details

#initialize(field_name, **generator_opts, &block) ⇒ Callback

Returns a new instance of Callback.



8
9
10
11
# File 'lib/randomized_field/callback.rb', line 8

def initialize(field_name, **generator_opts, &block)
  @field_name = field_name
  @generator = Generator.new(generator_opts, &block)
end

Instance Method Details

#before_create(record) ⇒ Object



13
14
15
# File 'lib/randomized_field/callback.rb', line 13

def before_create(record)
  record[field_name] ||= new_field_value(record)
end