Module: Refinery::Validations::ClassMethods

Defined in:
lib/refinery/validations.rb

Overview

Class methods that are added to the worker.

Instance Method Summary collapse

Instance Method Details

#validate_key_exists(*args) ⇒ Object Also known as: validates_key_exists, validates_presence_of

Validate that each of the keys exists in the message.



29
30
31
32
33
34
35
# File 'lib/refinery/validations.rb', line 29

def validate_key_exists(*args)
  args.each do |key|
    validators << lambda do |message|
      raise Refinery::InvalidMessageError, "Key does not exist in message: #{key}" unless message[key]
    end
  end
end

#validate_with(&block) ⇒ Object Also known as: validate

Validate with the given block. The block must receive a single argument that is the message



23
24
25
# File 'lib/refinery/validations.rb', line 23

def validate_with(&block)
  validators << block
end

#validatorsObject

A list of all of the validators. Validators are lambdas that will be called with the message as its only arg. Note that the order of validators is retained.



17
18
19
# File 'lib/refinery/validations.rb', line 17

def validators
  @validators ||= []
end