Class: Fleck::Core::Consumer::Validation

Inherits:
Object
  • Object
show all
Defined in:
lib/fleck/core/consumer/validation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, value, modifier = nil, **options) ⇒ Validation

Returns a new instance of Validation.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fleck/core/consumer/validation.rb', line 9

def initialize(name, type, value, modifier = nil, **options)
  @name = name
  @type         = type
  @modifier     = modifier
  @value        = value || options[:default]
  @required     = (options[:required] == true)     # default: trues
  @allow_blank  = (options[:allow_blank] != false) # default: false
  @min          = options[:min]
  @max          = options[:max]
  @clamp        = options[:clamp] || [-Float::INFINITY, Float::INFINITY]

  @errors = []

  validate!
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'lib/fleck/core/consumer/validation.rb', line 7

def errors
  @errors
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/fleck/core/consumer/validation.rb', line 7

def value
  @value
end

Instance Method Details

#add_error(error_type, message) ⇒ Object



33
34
35
# File 'lib/fleck/core/consumer/validation.rb', line 33

def add_error(error_type, message)
  @errors << { type: 'param', name: @name, value: @value, error: error_type, message: message }
end

#required?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/fleck/core/consumer/validation.rb', line 29

def required?
  @required
end

#valid?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/fleck/core/consumer/validation.rb', line 25

def valid?
  @errors.empty?
end