Class: Respect::HashDef
Instance Method Summary (collapse)
-
- (Object) []=(key, value)
Shortcut to say a schema key must be equal to a given value.
- - (Object) extra(&block)
-
- (HashDef) initialize(options = {})
constructor
A new instance of HashDef.
Methods inherited from GlobalDef
#accept_name?, accept_name?, core_contexts, eval, #eval, include_core_statements
Constructor Details
- (HashDef) initialize(options = {})
A new instance of HashDef
5 6 7 |
# File 'lib/respect/hash_def.rb', line 5 def initialize( = {}) @hash_schema = HashSchema.new() end |
Instance Method Details
- (Object) []=(key, value)
Shortcut to say a schema key must be equal to a given value. When it does not recognize the value type it creates a "any" schema.
Example:
HashSchema.define do |s|
s["a_string"] = "value" # equivalent to: s.string("a_string", equal_to: "value")
s["a_key"] = 0..5 # equivalent to: s.any("a_key", equal_to: "0..5")
end
21 22 23 24 25 26 27 28 |
# File 'lib/respect/hash_def.rb', line 21 def []=(key, value) case value when String string(key, equal_to: value.to_s) else any(key, equal_to: value.to_s) end end |
- (Object) extra(&block)
9 10 11 |
# File 'lib/respect/hash_def.rb', line 9 def extra(&block) (required: false, &block) end |