Class: Remont::RecordProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/remont/record_processor.rb

Constant Summary collapse

NOOP =
proc {}

Instance Method Summary collapse

Constructor Details

#initialize(schema, before, after) ⇒ RecordProcessor

Returns a new instance of RecordProcessor.

Parameters:



8
9
10
11
12
# File 'lib/remont/record_processor.rb', line 8

def initialize(schema, before, after)
  @schema = schema
  @before = before || NOOP
  @after = after || NOOP
end

Instance Method Details

#process!(record) ⇒ ActiveRecord::Base

Returns record.

Parameters:

  • record (ActiveRecord::Base)

Returns:

  • (ActiveRecord::Base)

    record



16
17
18
19
20
21
22
23
24
# File 'lib/remont/record_processor.rb', line 16

def process!(record)
  before.call(record)
  record.update_columns( # rubocop:disable Rails/SkipsModelValidations
    processed_attributes(record)
  )
  after.call(record)

  record
end