Class: Jsm::Validators
- Inherits:
-
Object
- Object
- Jsm::Validators
- Defined in:
- lib/jsm/validators.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #add_validator(name, validator) ⇒ Object
-
#initialize ⇒ Validators
constructor
A new instance of Validators.
- #validate(name, obj) ⇒ Object
Constructor Details
#initialize ⇒ Validators
Returns a new instance of Validators.
2 3 4 |
# File 'lib/jsm/validators.rb', line 2 def initialize @list = Hash.new { |validators, state| validators[state] = [] } end |
Instance Method Details
#[](name) ⇒ Object
10 11 12 |
# File 'lib/jsm/validators.rb', line 10 def [](name) @list[name] end |
#add_validator(name, validator) ⇒ Object
6 7 8 |
# File 'lib/jsm/validators.rb', line 6 def add_validator(name, validator) @list[name].push(validator) end |
#validate(name, obj) ⇒ Object
14 15 16 |
# File 'lib/jsm/validators.rb', line 14 def validate(name, obj) @list[name].all? { |validator| validator.validate(obj) } end |