Class: Mimi::DB::Model

Inherits:
Object
  • Object
show all
Includes:
Dictate
Defined in:
lib/mimi/db/model.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Dictate

diff_schema, included, schema_definitions, start, update_schema!

Class Method Details

.before_validation(method = nil, &block) ⇒ Object

Defines a hook the ActiveRecord way

Example:

class A < Mimi::DB::Model
  before_validation :set_detaults

  def set_defaults
    self.name = "John Doe"
  end
end


38
39
40
41
42
43
44
# File 'lib/mimi/db/model.rb', line 38

def self.before_validation(method = nil, &block)
  if method && block
    raise ArgumentError, '.before_validation() cannot accept both method and a block'
  end
  block = -> { send(method) } if method
  register_hook(:before_validation, block)
end

Instance Method Details

#before_validationObject



21
22
23
24
# File 'lib/mimi/db/model.rb', line 21

def before_validation
  super
  call_hooks(:before_validation)
end

#default_validation_helpers_options(type) ⇒ Object

Keeps messages as error types, not human readable strings



17
18
19
# File 'lib/mimi/db/model.rb', line 17

def default_validation_helpers_options(type)
  { message: type }
end