Class: Restspec::Schema::Types::EmbeddedSchemaType
- Defined in:
- lib/restspec/schema/types/embedded_schema_type.rb
Overview
An embedded schema is an attribute with all the options of a given schema.
Instance Attribute Summary collapse
-
#schema_name ⇒ Object
Returns the value of attribute schema_name.
Instance Method Summary collapse
-
#example_for(attribute) ⇒ Object
Generates examples by creating a SchemaExample using the passed schema.
-
#initialize(schema_name, options = {}) ⇒ EmbeddedSchemaType
constructor
A new instance of EmbeddedSchemaType.
-
#valid?(attribute, value) ⇒ true, false
Checks if the value is an embedded valid example of the schema used to initialize.
Methods inherited from BasicType
#of, #to_s, #totally_valid?, #|
Constructor Details
#initialize(schema_name, options = {}) ⇒ EmbeddedSchemaType
Returns a new instance of EmbeddedSchemaType.
7 8 9 10 |
# File 'lib/restspec/schema/types/embedded_schema_type.rb', line 7 def initialize(schema_name, = {}) self.schema_name = schema_name super() end |
Instance Attribute Details
#schema_name ⇒ Object
Returns the value of attribute schema_name.
5 6 7 |
# File 'lib/restspec/schema/types/embedded_schema_type.rb', line 5 def schema_name @schema_name end |
Instance Method Details
#example_for(attribute) ⇒ Object
Generates examples by creating a SchemaExample using the passed schema.
16 17 18 |
# File 'lib/restspec/schema/types/embedded_schema_type.rb', line 16 def example_for(attribute) Restspec::Schema::SchemaExample.new(schema).value end |
#valid?(attribute, value) ⇒ true, false
Checks if the value is an embedded valid example of the schema used to initialize.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/restspec/schema/types/embedded_schema_type.rb', line 42 def valid?(attribute, value) begin Restspec::Schema::Checker.new(schema).check!(value) true rescue Restspec::Schema::Checker::NoAttributeError, Restspec::Schema::Checker::InvalidationError, Restspec::Schema::Checker::NoObjectError false end end |