Class: Kwalify::Rule
- Inherits:
-
Object
- Object
- Kwalify::Rule
- Includes:
- ErrorHelper
- Defined in:
- lib/kwalify/rule.rb
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.
-
#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
attr_reader :id.
-
#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
-
#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.
16 17 18 19 |
# File 'lib/kwalify/rule.rb', line 16 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.
33 34 35 |
# File 'lib/kwalify/rule.rb', line 33 def assert @assert end |
#assert_proc ⇒ Object (readonly)
Returns the value of attribute assert_proc.
34 35 36 |
# File 'lib/kwalify/rule.rb', line 34 def assert_proc @assert_proc end |
#classname ⇒ Object (readonly)
Returns the value of attribute classname.
39 40 41 |
# File 'lib/kwalify/rule.rb', line 39 def classname @classname end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
24 25 26 |
# File 'lib/kwalify/rule.rb', line 24 def desc @desc end |
#enum ⇒ Object (readonly)
Returns the value of attribute enum.
25 26 27 |
# File 'lib/kwalify/rule.rb', line 25 def enum @enum end |
#ident ⇒ Object (readonly)
Returns the value of attribute ident.
37 38 39 |
# File 'lib/kwalify/rule.rb', line 37 def ident @ident end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
36 37 38 |
# File 'lib/kwalify/rule.rb', line 36 def length @length end |
#mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
32 33 34 |
# File 'lib/kwalify/rule.rb', line 32 def mapping @mapping end |
#name ⇒ Object (readonly)
attr_reader :id
23 24 25 |
# File 'lib/kwalify/rule.rb', line 23 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
21 22 23 |
# File 'lib/kwalify/rule.rb', line 21 def parent @parent end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
29 30 31 |
# File 'lib/kwalify/rule.rb', line 29 def pattern @pattern end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
35 36 37 |
# File 'lib/kwalify/rule.rb', line 35 def range @range end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
30 31 32 |
# File 'lib/kwalify/rule.rb', line 30 def regexp @regexp end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
26 27 28 |
# File 'lib/kwalify/rule.rb', line 26 def required @required end |
#sequence ⇒ Object (readonly)
Returns the value of attribute sequence.
31 32 33 |
# File 'lib/kwalify/rule.rb', line 31 def sequence @sequence end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
27 28 29 |
# File 'lib/kwalify/rule.rb', line 27 def type @type end |
#type_class ⇒ Object (readonly)
Returns the value of attribute type_class.
28 29 30 |
# File 'lib/kwalify/rule.rb', line 28 def type_class @type_class end |
#unique ⇒ Object (readonly)
Returns the value of attribute unique.
38 39 40 |
# File 'lib/kwalify/rule.rb', line 38 def unique @unique end |
Instance Method Details
#init(hash, path = "", rule_table = {}) ⇒ Object
41 42 43 44 45 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 74 75 76 77 78 |
# File 'lib/kwalify/rule.rb', line 41 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 _init_type_value(hash['type'], rule, path) ## other entries hash.each do |key, val| code = key.intern curr_path = "#{path}/#{key}" case code #when "id" # @id = val when :type ; # done when :name ; _init_name_value( val, rule, path) when :desc ; _init_desc_value( val, rule, path) when :required ; _init_required_value(val, rule, path) when :pattern ; _init_pattern_value( val, rule, path) when :enum ; _init_enum_value( val, rule, path) when :assert ; _init_assert_value( val, rule, path) when :range ; _init_range_value( val, rule, path) when :length ; _init_length_value( val, rule, path) when :ident ; _init_ident_value( val, rule, path) when :unique ; _init_unique_value( val, rule, path) when :sequence ; _init_sequence_value(val, rule, path, rule_table) when :mapping ; _init_mapping_value( val, rule, path, rule_table) when :classname ; _init_classname_value(val, rule, path) else #* key=:key_unknown msg="unknown key." raise schema_error(:key_unknown, rule, curr_path, "#{key}:") end end check_confliction(hash, rule, path) return self end |