Class: Fakerize::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/fakerize/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, config = {}) ⇒ Model

Returns a new instance of Model.



4
5
6
7
# File 'lib/fakerize/model.rb', line 4

def initialize(model, config = {})
  @model = model
  @config = Fakerize::Configuration.new default_config.merge(config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



2
3
4
# File 'lib/fakerize/model.rb', line 2

def config
  @config
end

#modelObject (readonly)

Returns the value of attribute model.



2
3
4
# File 'lib/fakerize/model.rb', line 2

def model
  @model
end

Instance Method Details

#performObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fakerize/model.rb', line 9

def perform
  config.attributes.each do |attribute|
    # Example: user.first_name=
    model.send "#{attribute}=", config.send(attribute).call
  end

  # Example: :remove_profile_image!
  before_save_methods.each { |method| model.send(method) }

  model.save!
end