Class: Polytrix::ValidatorRegistry
- Inherits:
-
Object
- Object
- Polytrix::ValidatorRegistry
- Includes:
- Singleton
- Defined in:
- lib/polytrix/validator_registry.rb
Class Method Summary collapse
- .clear ⇒ Object
- .register(validator, scope = {}, &callback) ⇒ Object
- .validators ⇒ Object
- .validators_for(challenge) ⇒ Object
Instance Method Summary collapse
Class Method Details
.clear ⇒ Object
26 27 28 |
# File 'lib/polytrix/validator_registry.rb', line 26 def clear validators.clear end |
.register(validator, scope = {}, &callback) ⇒ Object
16 17 18 19 |
# File 'lib/polytrix/validator_registry.rb', line 16 def register(validator, scope = {}, &callback) validator = Validator.new(validator, scope, &callback) if block_given? validators << validator end |
.validators ⇒ Object
12 13 14 |
# File 'lib/polytrix/validator_registry.rb', line 12 def validators instance.validators end |
.validators_for(challenge) ⇒ Object
21 22 23 24 |
# File 'lib/polytrix/validator_registry.rb', line 21 def validators_for(challenge) selected_validators = validators.select { |v| v.should_validate? challenge } selected_validators.empty? ? [Polytrix.configuration.default_validator] : selected_validators end |
Instance Method Details
#validators ⇒ Object
7 8 9 |
# File 'lib/polytrix/validator_registry.rb', line 7 def validators @validator ||= [] end |