Class: Compel::Validation::Condition

Inherits:
Object
  • Object
show all
Defined in:
lib/compel/validation/conditions/condition.rb

Direct Known Subclasses

Format, If, In, Is, Length, Max, MaxLength, Min, MinLength

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, option_value, options = {}) ⇒ Condition

Returns a new instance of Condition.



15
16
17
18
19
20
# File 'lib/compel/validation/conditions/condition.rb', line 15

def initialize(value, option_value, options = {})
  @value = value
  @value_type = options.delete(:type) || Coercion::Types::Any
  @options = options
  @option_value = option_value
end

Instance Attribute Details

#option_valueObject (readonly)

Returns the value of attribute option_value.



6
7
8
# File 'lib/compel/validation/conditions/condition.rb', line 6

def option_value
  @option_value
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/compel/validation/conditions/condition.rb', line 6

def options
  @options
end

#valueObject (readonly)

Returns the value of attribute value.



6
7
8
# File 'lib/compel/validation/conditions/condition.rb', line 6

def value
  @value
end

#value_typeObject (readonly)

Returns the value of attribute value_type.



6
7
8
# File 'lib/compel/validation/conditions/condition.rb', line 6

def value_type
  @value_type
end

Class Method Details

.validate(value, option_value, options = {}) ⇒ Object



11
12
13
# File 'lib/compel/validation/conditions/condition.rb', line 11

def self.validate(value, option_value, options = {})
  new(value, option_value, options).validate
end

Instance Method Details

#validateObject



22
23
24
25
# File 'lib/compel/validation/conditions/condition.rb', line 22

def validate
  Validation::Result.new \
    value, value_type, validate_value_with_error_message
end