Class: Schemacop::V2::FieldNode
- Inherits:
-
NodeSupportingType
- Object
- Node
- NodeWithBlock
- NodeSupportingType
- Schemacop::V2::FieldNode
- Defined in:
- lib/schemacop/v2/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/v2/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/v2/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 25 26 27 28 29 30 |
# File 'lib/schemacop/v2/field_node.rb', line 16 def validate(data, collector) if !data.key?(name) && @required collector.error "Missing key #{name.inspect}." end collector.path "/#{name}", name, :hash do value, default_applied = apply_default!(data[name], collector) unless data.key?(name) || default_applied next end super(value, collector) end end |