Module: SmartCore::Validator::DSL Private
- Included in:
- SmartCore::Validator
- Defined in:
- lib/smart_core/validator/dsl.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Class Method Summary collapse
- .extended(base_klass) ⇒ void private
Instance Method Summary collapse
- #attribute(attribute_name, default: nil) ⇒ void
- #attributes ⇒ SmartCore::Validator::AttributeSet private
- #clear_commands ⇒ void private
- #commands ⇒ SmartCore::Validator::CommandSet private
- #validate(validating_method, &nested_validations) ⇒ void
- #validate_with(validating_klass, &nested_validations) ⇒ void
Class Method Details
.extended(base_klass) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/smart_core/validator/dsl.rb', line 13 def extended(base_klass) base_klass.instance_variable_set(:@__commands__, CommandSet.new) base_klass.instance_variable_set(:@__attributes__, AttributeSet.new) base_klass.singleton_class.prepend(Module.new do def inherited(child_klass) child_klass.instance_variable_set(:@__commands__, CommandSet.new) child_klass.instance_variable_set(:@__attributes__, AttributeSet.new) child_klass.commands.concat(commands) child_klass.attributes.concat(attributes) super(child_klass) end end) end |
Instance Method Details
#attribute(attribute_name, default: nil) ⇒ void
This method returns an undefined value.
36 37 38 39 40 |
# File 'lib/smart_core/validator/dsl.rb', line 36 def attribute(attribute_name, default: nil) attribute = SmartCore::Validator::Attribute.new(attribute_name, default) attributes << attribute attr_reader attribute.name end |
#attributes ⇒ SmartCore::Validator::AttributeSet
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 |
# File 'lib/smart_core/validator/dsl.rb', line 46 def attributes @__attributes__ end |
#clear_commands ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
62 63 64 |
# File 'lib/smart_core/validator/dsl.rb', line 62 def clear_commands commands.clear end |
#commands ⇒ SmartCore::Validator::CommandSet
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 |
# File 'lib/smart_core/validator/dsl.rb', line 54 def commands @__commands__ end |
#validate(validating_method, &nested_validations) ⇒ void
This method returns an undefined value.
75 76 77 78 79 80 81 |
# File 'lib/smart_core/validator/dsl.rb', line 75 def validate(validating_method, &nested_validations) if block_given? commands << Commands::AddNestedValidations.new(validating_method, nested_validations) else commands << Commands::AddValidation.new(validating_method) end end |
#validate_with(validating_klass, &nested_validations) ⇒ void
This method returns an undefined value.
91 92 93 |
# File 'lib/smart_core/validator/dsl.rb', line 91 def validate_with(validating_klass, &nested_validations) commands << Commands::ValidateWith.new(validating_klass, nested_validations) end |