Class: Ree::Contracts::ArgContracts::Or
Direct Known Subclasses
Instance Attribute Summary collapse
-
#validators ⇒ Object
readonly
Returns the value of attribute validators.
Instance Method Summary collapse
-
#initialize(*contracts) ⇒ Or
constructor
A new instance of Or.
- #message(value, name, lvl = 1) ⇒ Object
- #to_s ⇒ Object
- #valid?(value) ⇒ Boolean
Methods included from Squarable
Methods included from Truncatable
Constructor Details
#initialize(*contracts) ⇒ Or
Returns a new instance of Or.
11 12 13 |
# File 'lib/ree/contracts/arg_contracts/or.rb', line 11 def initialize(*contracts) @validators = contracts.map(&Validators.method(:fetch_for)) end |
Instance Attribute Details
#validators ⇒ Object (readonly)
Returns the value of attribute validators.
9 10 11 |
# File 'lib/ree/contracts/arg_contracts/or.rb', line 9 def validators @validators end |
Instance Method Details
#message(value, name, lvl = 1) ⇒ Object
25 26 27 |
# File 'lib/ree/contracts/arg_contracts/or.rb', line 25 def (value, name, lvl = 1) "expected #{truncate(self.to_s, 30)}, got #{truncate(value.inspect)}" end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/ree/contracts/arg_contracts/or.rb', line 15 def to_s "Or[#{validators.map(&:to_s).join(', ')}]" end |
#valid?(value) ⇒ Boolean
19 20 21 22 23 |
# File 'lib/ree/contracts/arg_contracts/or.rb', line 19 def valid?(value) validators.any? do |validator| validator.call(value) end end |