Class: Dry::Validation::Schema::Value
Instance Attribute Summary collapse
-
#checks ⇒ Object
readonly
Returns the value of attribute checks.
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(name) ⇒ Value
constructor
A new instance of Value.
Methods included from Definition
#attr, #confirmation, #key, #optional, #rule, #schema, #value
Constructor Details
#initialize(name) ⇒ Value
Returns a new instance of Value.
9 10 11 12 13 14 |
# File 'lib/dry/validation/schema/value.rb', line 9 def initialize(name) @name = name @rules = [] @groups = [] @checks = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object (private)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dry/validation/schema/value.rb', line 31 def method_missing(meth, *args, &block) rule = Schema::Rule.new(name, [:val, [name, [:predicate, [meth, args]]]]) if block val_rule = yield if val_rule.is_a?(Schema::Rule) rule & val_rule else Schema::Rule.new(name, [:and, [rule.to_ary, [:set, [name, rules.map(&:to_ary)]]]]) end else rule end end |
Instance Attribute Details
#checks ⇒ Object (readonly)
Returns the value of attribute checks.
7 8 9 |
# File 'lib/dry/validation/schema/value.rb', line 7 def checks @checks end |
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
7 8 9 |
# File 'lib/dry/validation/schema/value.rb', line 7 def groups @groups end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/dry/validation/schema/value.rb', line 7 def name @name end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
7 8 9 |
# File 'lib/dry/validation/schema/value.rb', line 7 def rules @rules end |
Instance Method Details
#each(&block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dry/validation/schema/value.rb', line 16 def each(&block) val_rule = yield(self) each_rule = if val_rule.is_a?(Schema::Rule) val_rule.to_ary else [:set, [name, rules.map(&:to_ary)]] end Schema::Rule.new(name, [:each, [name, each_rule]]) end |