Module: Ephemeron::Validators::BeforeSave

Defined in:
lib/ephemeron/validators/before_save.rb

Class Method Summary collapse

Class Method Details

.call(model) ⇒ Object

Raises:



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ephemeron/validators/before_save.rb', line 8

def call(model)
  return unless Ephemeron::Store.has? model

  last_event = Ephemeron::Logger::Finders
               .find_all_events_for(model, :save_allowed, :saved)
               .last
  return if last_event == Logger::Convert.call(model, :save_allowed)

  msg = "prior persistence for #{Ephemeron::Store::Convert.call(model)} is prohibited"
  raise(PersistenceError, msg)
end