Class: Kwalify::Rule
- Inherits:
-
Object
- Object
- Kwalify::Rule
- Includes:
- ErrorHelper
- Defined in:
- lib/kwalify/rule.rb
Constant Summary collapse
- @@dispatch_table =
table
Instance Attribute Summary collapse
-
#assert ⇒ Object
readonly
Returns the value of attribute assert.
-
#assert_proc ⇒ Object
readonly
Returns the value of attribute assert_proc.
-
#classname ⇒ Object
readonly
Returns the value of attribute classname.
-
#classobj ⇒ Object
readonly
Returns the value of attribute classobj.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#enum ⇒ Object
readonly
Returns the value of attribute enum.
-
#ident ⇒ Object
readonly
Returns the value of attribute ident.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#mapping ⇒ Object
readonly
Returns the value of attribute mapping.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#sequence ⇒ Object
readonly
Returns the value of attribute sequence.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#type_class ⇒ Object
readonly
Returns the value of attribute type_class.
-
#unique ⇒ Object
readonly
Returns the value of attribute unique.
Instance Method Summary collapse
- #_init(hash, path = "", rule_table = {}) ⇒ Object
-
#_uniqueness_check_table ⇒ Object
:nodoc:.
-
#initialize(hash = nil, parent = nil) ⇒ Rule
constructor
A new instance of Rule.
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
#assert ⇒ Object (readonly)
Returns the value of attribute assert.
29 30 31 |
# File 'lib/kwalify/rule.rb', line 29 def assert @assert end |
#assert_proc ⇒ Object (readonly)
Returns the value of attribute assert_proc.
30 31 32 |
# File 'lib/kwalify/rule.rb', line 30 def assert_proc @assert_proc end |
#classname ⇒ Object (readonly)
Returns the value of attribute classname.
36 37 38 |
# File 'lib/kwalify/rule.rb', line 36 def classname @classname end |
#classobj ⇒ Object (readonly)
Returns the value of attribute classobj.
37 38 39 |
# File 'lib/kwalify/rule.rb', line 37 def classobj @classobj end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
35 36 37 |
# File 'lib/kwalify/rule.rb', line 35 def default @default end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
20 21 22 |
# File 'lib/kwalify/rule.rb', line 20 def desc @desc end |
#enum ⇒ Object (readonly)
Returns the value of attribute enum.
21 22 23 |
# File 'lib/kwalify/rule.rb', line 21 def enum @enum end |
#ident ⇒ Object (readonly)
Returns the value of attribute ident.
33 34 35 |
# File 'lib/kwalify/rule.rb', line 33 def ident @ident end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
32 33 34 |
# File 'lib/kwalify/rule.rb', line 32 def length @length end |
#mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
28 29 30 |
# File 'lib/kwalify/rule.rb', line 28 def mapping @mapping end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/kwalify/rule.rb', line 19 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
18 19 20 |
# File 'lib/kwalify/rule.rb', line 18 def parent @parent end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
25 26 27 |
# File 'lib/kwalify/rule.rb', line 25 def pattern @pattern end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
31 32 33 |
# File 'lib/kwalify/rule.rb', line 31 def range @range end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
26 27 28 |
# File 'lib/kwalify/rule.rb', line 26 def regexp @regexp end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
22 23 24 |
# File 'lib/kwalify/rule.rb', line 22 def required @required end |
#sequence ⇒ Object (readonly)
Returns the value of attribute sequence.
27 28 29 |
# File 'lib/kwalify/rule.rb', line 27 def sequence @sequence end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
23 24 25 |
# File 'lib/kwalify/rule.rb', line 23 def type @type end |
#type_class ⇒ Object (readonly)
Returns the value of attribute type_class.
24 25 26 |
# File 'lib/kwalify/rule.rb', line 24 def type_class @type_class end |
#unique ⇒ Object (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_table ⇒ Object
: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 |