Class: YFantasy::SubresourceValidator
- Inherits:
-
Object
- Object
- YFantasy::SubresourceValidator
- Defined in:
- lib/y_fantasy/subresource_validator.rb
Defined Under Namespace
Classes: Contract, InvalidSubresourceError
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(klass, subresources = []) ⇒ SubresourceValidator
constructor
A new instance of SubresourceValidator.
- #validate! ⇒ Object
Constructor Details
#initialize(klass, subresources = []) ⇒ SubresourceValidator
Returns a new instance of SubresourceValidator.
9 10 11 12 |
# File 'lib/y_fantasy/subresource_validator.rb', line 9 def initialize(klass, subresources = []) @contract = Contract.new(klass: klass) @subresources = Array(subresources) end |
Class Method Details
.validate!(klass, subresources = []) ⇒ Object
5 6 7 |
# File 'lib/y_fantasy/subresource_validator.rb', line 5 def self.validate!(klass, subresources = []) new(klass, subresources).validate! end |
Instance Method Details
#validate! ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/y_fantasy/subresource_validator.rb', line 14 def validate! return true if @subresources.empty? result = @contract.call(subresources: @subresources) return true if result.success? raise InvalidSubresourceError.new(result.errors.to_h.to_s) end |