Class: Polytrix::ValidatorRegistry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/polytrix/validator_registry.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clearObject



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

.validatorsObject



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

#validatorsObject



7
8
9
# File 'lib/polytrix/validator_registry.rb', line 7

def validators
  @validator ||= []
end