Class: Restspec::Schema::Types::HashType
- Defined in:
- lib/restspec/schema/types/hash_type.rb
Overview
It represent embedded hashes, but not schematic ones. For them use the EmbeddedSchemaType.
This Hash can receive the following options:
- schema_options:
- value_type: A type specifying the type of the values of the hash.
- keys: What are the keys that should be present in the hash.
Instance Method Summary collapse
-
#example_for(attribute) ⇒ Hash
Generates an empty hash for a example.
-
#valid?(attribute, value) ⇒ true, false
Checks if the object is a valid hash with the specified keys if they are specified or the specified value type.
Methods inherited from BasicType
#initialize, #of, #to_s, #totally_valid?, #|
Constructor Details
This class inherits a constructor from Restspec::Schema::Types::BasicType
Instance Method Details
#example_for(attribute) ⇒ Hash
Generates an empty hash for a example. It could be better soon.
17 18 19 |
# File 'lib/restspec/schema/types/hash_type.rb', line 17 def example_for(attribute) {} end |
#valid?(attribute, value) ⇒ true, false
Checks if the object is a valid hash with the specified keys if they are specified or the specified value type.
40 41 42 |
# File 'lib/restspec/schema/types/hash_type.rb', line 40 def valid?(attribute, value) value.is_a?(Hash) && valid_keys?(value) && valid_value_types?(attribute, value) end |