Class: FlexValidations::Decorate

Inherits:
Object
  • Object
show all
Includes:
Validation
Defined in:
lib/flex_validations/decorate.rb

Overview

Not a really validation but handy class for complex validations

Examples:

hash = FlexValidations::Chain.new(
  FlexValidations::Call.new(:keys),
  FlexValidations::Decorate.new(Set),
  FlexValidations::Predicate.new(:==, Set.new(["id", "title"]))
)

Defined Under Namespace

Classes: SuccessMessage

Instance Method Summary collapse

Methods included from Validation

#===, #to_proc

Constructor Details

#initialize(decorator_class, *decorator_args) ⇒ Decorate

Returns a new instance of Decorate.



15
16
17
18
# File 'lib/flex_validations/decorate.rb', line 15

def initialize(decorator_class, *decorator_args)
  @decorator_class = decorator_class
  @decorator_args = decorator_args
end

Instance Method Details

#to_sString

Returns:

  • (String)


30
31
32
# File 'lib/flex_validations/decorate.rb', line 30

def to_s
  "decorate value with #{@decorator_class}"
end

#validate(value) ⇒ FlexValidations::Result

Parameters:

  • value (Object)

    Value to be validated

Returns:



23
24
25
26
27
# File 'lib/flex_validations/decorate.rb', line 23

def validate(value)
  new_val = @decorator_class.new value, *@decorator_args

  Result::Success::Simple.new(self, SuccessMessage.new(value, new_val), value, new_val)
end