Class: Membrane::Schemas::Record
- Defined in:
- lib/membrane/schemas/record.rb
Defined Under Namespace
Classes: HashValidator, KeyValidator
Instance Attribute Summary collapse
-
#optional_keys ⇒ Object
readonly
Returns the value of attribute optional_keys.
-
#schemas ⇒ Object
readonly
Returns the value of attribute schemas.
Instance Method Summary collapse
-
#initialize(schemas, optional_keys = [], strict_checking = false) ⇒ Record
constructor
A new instance of Record.
- #parse(&blk) ⇒ Object
- #validate(object) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(schemas, optional_keys = [], strict_checking = false) ⇒ Record
Returns a new instance of Record.
15 16 17 18 19 |
# File 'lib/membrane/schemas/record.rb', line 15 def initialize(schemas, optional_keys = [], strict_checking = false) @optional_keys = Set.new(optional_keys) @schemas = schemas @strict_checking = strict_checking end |
Instance Attribute Details
#optional_keys ⇒ Object (readonly)
Returns the value of attribute optional_keys.
13 14 15 |
# File 'lib/membrane/schemas/record.rb', line 13 def optional_keys @optional_keys end |
#schemas ⇒ Object (readonly)
Returns the value of attribute schemas.
12 13 14 |
# File 'lib/membrane/schemas/record.rb', line 12 def schemas @schemas end |
Instance Method Details
#parse(&blk) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/membrane/schemas/record.rb', line 26 def parse(&blk) other_record = Membrane::SchemaParser.parse(&blk) @schemas.merge!(other_record.schemas) @optional_keys << other_record.optional_keys self end |
#validate(object) ⇒ Object
21 22 23 24 |
# File 'lib/membrane/schemas/record.rb', line 21 def validate(object) HashValidator.new(object).validate KeyValidator.new(@optional_keys, @schemas, @strict_checking, object).validate end |