Module: ROM::Model::Validator::ClassMethods

Defined in:
lib/rom/rails/model/validator.rb

Instance Method Summary collapse

Instance Method Details

#call(attributes) ⇒ Model::Attributes

Trigger validation for specific attributes

Parameters:

Returns:



114
115
116
117
# File 'lib/rom/rails/model/validator.rb', line 114

def call(attributes)
  validator = new(attributes)
  validator.call
end

#model_nameObject

FIXME: this looks like not needed



103
104
105
# File 'lib/rom/rails/model/validator.rb', line 103

def model_name
  attributes.model_name
end

#relation(name = nil) ⇒ Symbol

Set relation name for a validator

This is needed for validators that require database access

Examples:


class UserValidator
  include ROM::Model::Validator

  relation :users

  validates :name, uniqueness: true
end

Returns:

  • (Symbol)


97
98
99
100
# File 'lib/rom/rails/model/validator.rb', line 97

def relation(name = nil)
  @relation = name if name
  @relation
end