Class: Wallaby::ActiveRecord::ModelServiceProvider::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/adapters/wallaby/active_record/model_service_provider/validator.rb

Overview

Validate values for record create / update

Instance Method Summary collapse

Constructor Details

#initialize(model_decorator) ⇒ Validator

Returns a new instance of Validator.

Parameters:

  • model_decorator (Wallaby::ModelDecorator)


9
10
11
# File 'lib/adapters/wallaby/active_record/model_service_provider/validator.rb', line 9

def initialize(model_decorator)
  @model_decorator = model_decorator
end

Instance Method Details

#valid?(resource) ⇒ true, false

Parameters:

  • resource (Object)

    resource object

Returns:

  • (true)

    if the resource object is valid

  • (false)

    otherwise



16
17
18
19
20
21
22
23
24
# File 'lib/adapters/wallaby/active_record/model_service_provider/validator.rb', line 16

def valid?(resource)
  resource.attributes.each do |field_name, values|
     = @model_decorator.fields[field_name]
    next if valid_range_type? values, 

    resource.errors.add field_name, 'required for range data'
  end
  resource.errors.blank?
end