Class: Schemacop::FieldNode
- Inherits:
-
NodeSupportingType
- Object
- Node
- NodeWithBlock
- NodeSupportingType
- Schemacop::FieldNode
- Defined in:
- lib/schemacop/field_node.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Node
Instance Method Summary collapse
-
#initialize(name, required, options = {}, &block) ⇒ FieldNode
constructor
A new instance of FieldNode.
- #validate(data, collector) ⇒ Object
Methods inherited from NodeSupportingType
Methods inherited from NodeWithBlock
Methods inherited from Node
build, class_matches?, clear_klasses, clear_symbols, #exec_block, klass, option, #option, #option?, register, #resolve_type_klass, symbol, symbol_matches?, #type_filter_matches?, #type_label, type_matches?, #type_matches?
Constructor Details
#initialize(name, required, options = {}, &block) ⇒ FieldNode
Returns a new instance of FieldNode
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/schemacop/field_node.rb', line 5 def initialize(name, required, = {}, &block) if .any? fail Exceptions::InvalidSchemaError, 'Node does not support options.' end super({}, &block) @name = name @required = required end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name
3 4 5 |
# File 'lib/schemacop/field_node.rb', line 3 def name @name end |
Instance Method Details
#validate(data, collector) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/schemacop/field_node.rb', line 16 def validate(data, collector) unless data.key?(name) collector.error "Missing key #{name.inspect}." if @required return end collector.path "/#{name}" do super(data[name], collector) end end |