Class: TableSchema::Constraints

Inherits:
Object
  • Object
show all
Includes:
Enum, MaxLength, Maximum, MinLength, Minimum, Pattern, Required, Unique, Helpers
Defined in:
lib/tableschema/constraints/enum.rb,
lib/tableschema/constraints/unique.rb,
lib/tableschema/constraints/maximum.rb,
lib/tableschema/constraints/minimum.rb,
lib/tableschema/constraints/pattern.rb,
lib/tableschema/constraints/required.rb,
lib/tableschema/constraints/max_length.rb,
lib/tableschema/constraints/min_length.rb,
lib/tableschema/constraints/constraints.rb

Defined Under Namespace

Modules: Enum, MaxLength, Maximum, MinLength, Minimum, Pattern, Required, Unique

Instance Method Summary collapse

Methods included from Unique

#check_unique

Methods included from Pattern

#check_pattern

Methods included from Enum

#check_enum, #parsed_enum

Methods included from Maximum

#check_maximum, #parsed_maximum

Methods included from Minimum

#check_minimum, #parsed_minimum

Methods included from MaxLength

#check_max_length, #parsed_max_length

Methods included from MinLength

#check_min_length, #parsed_min_length

Methods included from Required

#check_required

Methods included from Helpers

#deep_symbolize_keys, #get_class_for_type, #type_class_lookup

Constructor Details

#initialize(field, value) ⇒ Constraints

Returns a new instance of Constraints.



23
24
25
26
27
# File 'lib/tableschema/constraints/constraints.rb', line 23

def initialize(field, value)
  @field = field
  @value = value
  @constraints = ordered_constraints
end

Instance Method Details

#validate!Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tableschema/constraints/constraints.rb', line 29

def validate!
  result = true
  @constraints.each do |c|
    constraint = c.first.to_s
    if is_supported_type?(constraint)
      result = self.send("check_#{underscore constraint}")
    else
      raise(TableSchema::ConstraintNotSupported.new("The field type `#{@field[:type]}` does not support the `#{constraint}` constraint"))
    end
  end
  result
end