Class: Validation

Inherits:
Object
  • Object
show all
Defined in:
lib/yodel/models/core/validations/validation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Validation

Returns a new instance of Validation.



28
29
30
# File 'lib/yodel/models/core/validations/validation.rb', line 28

def initialize(params)
  @params = params
end

Instance Attribute Details

#fieldObject

Returns the value of attribute field.



2
3
4
# File 'lib/yodel/models/core/validations/validation.rb', line 2

def field
  @field
end

#paramsObject

Returns the value of attribute params.



2
3
4
# File 'lib/yodel/models/core/validations/validation.rb', line 2

def params
  @params
end

Class Method Details

.validate(type, params, field, name, value, record, errors) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/yodel/models/core/validations/validation.rb', line 4

def self.validate(type, params, field, name, value, record, errors)
  validation = case type
  when 'excluded_from'
    ExcludedFromValidation
  when 'excludes_combinations'
    ExcludesCombinationsValidation
  when 'format'
    FormatValidation
  when 'included_in'
    IncludedInValidation
  when 'includes_combinations'
    IncludesCombinationsValidation
  when 'length'
    LengthValidation
  when 'required'
    RequiredValidation
  when 'unique'
    UniqueValidation
  when 'password_confirmation'
    PasswordConfirmationValidation
  end
  validation.validate(params, field, name, value, record, errors)
end

Instance Method Details

#describeObject



32
33
34
# File 'lib/yodel/models/core/validations/validation.rb', line 32

def describe
  "is invalid"
end

#to_json(*a) ⇒ Object



36
37
38
# File 'lib/yodel/models/core/validations/validation.rb', line 36

def to_json(*a)
  describe.to_json(*a)
end