Class: DynamicValidation::BlockValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/dynamic_validation.rb

Overview

BlockValidator is a wrapper validator allow for blocks / lambda to be passed at dynamically at runtime instead of having to pass in an object. This will allow for quick and dirty validations, that don't need to be pulled into their own objects just yet.

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BlockValidator

Returns a new instance of BlockValidator



92
93
94
# File 'lib/dynamic_validation.rb', line 92

def initialize(options)
  @block = options.fetch(:block)
end

Instance Method Details

#validate(record) ⇒ Object



96
97
98
# File 'lib/dynamic_validation.rb', line 96

def validate(record)
  @block.call(record)
end