Class: RSchema::Schemas::Predicate
- Inherits:
-
Object
- Object
- RSchema::Schemas::Predicate
- Defined in:
- lib/rschema/schemas/predicate.rb
Overview
A schema that uses a given block to determine whether a value is valid
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #call(value, _options) ⇒ Object
-
#initialize(name = nil, &block) ⇒ Predicate
constructor
A new instance of Predicate.
- #with_wrapped_subschemas(_wrapper) ⇒ Object
Constructor Details
#initialize(name = nil, &block) ⇒ Predicate
Returns a new instance of Predicate.
18 19 20 21 |
# File 'lib/rschema/schemas/predicate.rb', line 18 def initialize(name = nil, &block) @block = block @name = name end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
16 17 18 |
# File 'lib/rschema/schemas/predicate.rb', line 16 def block @block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/rschema/schemas/predicate.rb', line 16 def name @name end |
Instance Method Details
#call(value, _options) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/rschema/schemas/predicate.rb', line 23 def call(value, ) if block.call(value) Result.success(value) else Result.failure(error(value)) end end |
#with_wrapped_subschemas(_wrapper) ⇒ Object
31 32 33 |
# File 'lib/rschema/schemas/predicate.rb', line 31 def with_wrapped_subschemas(_wrapper) self end |