Class: Kwalify::Rule

Inherits:
Object
  • Object
show all
Includes:
ErrorHelper
Defined in:
lib/kwalify/rule.rb

Constant Summary collapse

@@dispatch_table =
table

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ErrorHelper

_build_message, #assert_error, #schema_error, validate_error

Constructor Details

#initialize(hash = nil, parent = nil) ⇒ Rule

Returns a new instance of Rule.



40
41
42
43
# File 'lib/kwalify/rule.rb', line 40

def initialize(hash=nil, parent=nil)
  _init(hash, "", {}) if hash
  @parent = parent
end

Instance Attribute Details

#assertObject (readonly)

Returns the value of attribute assert.



29
30
31
# File 'lib/kwalify/rule.rb', line 29

def assert
  @assert
end

#assert_procObject (readonly)

Returns the value of attribute assert_proc.



30
31
32
# File 'lib/kwalify/rule.rb', line 30

def assert_proc
  @assert_proc
end

#classnameObject (readonly)

Returns the value of attribute classname.



36
37
38
# File 'lib/kwalify/rule.rb', line 36

def classname
  @classname
end

#classobjObject (readonly)

Returns the value of attribute classobj.



37
38
39
# File 'lib/kwalify/rule.rb', line 37

def classobj
  @classobj
end

#defaultObject (readonly)

Returns the value of attribute default.



35
36
37
# File 'lib/kwalify/rule.rb', line 35

def default
  @default
end

#descObject (readonly)

Returns the value of attribute desc.



20
21
22
# File 'lib/kwalify/rule.rb', line 20

def desc
  @desc
end

#enumObject (readonly)

Returns the value of attribute enum.



21
22
23
# File 'lib/kwalify/rule.rb', line 21

def enum
  @enum
end

#identObject (readonly)

Returns the value of attribute ident.



33
34
35
# File 'lib/kwalify/rule.rb', line 33

def ident
  @ident
end

#lengthObject (readonly)

Returns the value of attribute length.



32
33
34
# File 'lib/kwalify/rule.rb', line 32

def length
  @length
end

#mappingObject (readonly)

Returns the value of attribute mapping.



28
29
30
# File 'lib/kwalify/rule.rb', line 28

def mapping
  @mapping
end

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/kwalify/rule.rb', line 19

def name
  @name
end

#parentObject

Returns the value of attribute parent.



18
19
20
# File 'lib/kwalify/rule.rb', line 18

def parent
  @parent
end

#patternObject (readonly)

Returns the value of attribute pattern.



25
26
27
# File 'lib/kwalify/rule.rb', line 25

def pattern
  @pattern
end

#rangeObject (readonly)

Returns the value of attribute range.



31
32
33
# File 'lib/kwalify/rule.rb', line 31

def range
  @range
end

#regexpObject (readonly)

Returns the value of attribute regexp.



26
27
28
# File 'lib/kwalify/rule.rb', line 26

def regexp
  @regexp
end

#requiredObject (readonly)

Returns the value of attribute required.



22
23
24
# File 'lib/kwalify/rule.rb', line 22

def required
  @required
end

#sequenceObject (readonly)

Returns the value of attribute sequence.



27
28
29
# File 'lib/kwalify/rule.rb', line 27

def sequence
  @sequence
end

#typeObject (readonly)

Returns the value of attribute type.



23
24
25
# File 'lib/kwalify/rule.rb', line 23

def type
  @type
end

#type_classObject (readonly)

Returns the value of attribute type_class.



24
25
26
# File 'lib/kwalify/rule.rb', line 24

def type_class
  @type_class
end

#uniqueObject (readonly)

Returns the value of attribute unique.



34
35
36
# File 'lib/kwalify/rule.rb', line 34

def unique
  @unique
end

Instance Method Details

#_init(hash, path = "", rule_table = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/kwalify/rule.rb', line 46

def _init(hash, path="", rule_table={})
  unless hash.is_a?(Hash)
    #* key=:schema_notmap  msg="schema definition is not a mapping."
    raise Kwalify.schema_error(:schema_notmap, nil, (!path || path.empty? ? "/" : path), nil)
  end
  rule = self
  rule_table[hash.__id__] = rule
  ## 'type:' entry
  curr_path = "#{path}/type"
  _init_type_value(hash['type'], rule, curr_path)
  ## other entries
  hash.each do |key, val|
    curr_path = "#{path}/#{key}"
    sym = key.intern
    method = get_init_method(sym)
    unless method
      #* key=:key_unknown  msg="unknown key."
      raise schema_error(:key_unknown, rule, curr_path, "#{key}:")
    end
    if sym == :sequence || sym == :mapping
      __send__(method, val, rule, curr_path, rule_table)
    else
      __send__(method, val, rule, curr_path)
    end
  end
  _check_confliction(hash, rule, path)
  return self
end

#_uniqueness_check_tableObject

:nodoc:



539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'lib/kwalify/rule.rb', line 539

def _uniqueness_check_table()   # :nodoc:
  uniq_table = nil
  if @type == 'map'
    @mapping.keys.each do |key|
      rule = @mapping[key]
      if rule.unique || rule.ident
        uniq_table ||= {}
        uniq_table[key] = {}
      end
    end
  elsif @unique || @ident
    uniq_table = {}
  end
  return uniq_table
end