Class: VBS::Requests::Base
- Inherits:
-
Object
- Object
- VBS::Requests::Base
- Defined in:
- lib/vbs/requests/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Class Method Summary collapse
Instance Method Summary collapse
- #http_method ⇒ Object
- #path ⇒ Object
- #valid? ⇒ Boolean
- #validate! ⇒ Object
- #validate_request_model! ⇒ Object private
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/vbs/requests/base.rb', line 8 def errors @errors end |
Class Method Details
.schema_validation_options ⇒ Object
10 11 12 13 14 15 |
# File 'lib/vbs/requests/base.rb', line 10 def self. { errors_as_objects: true, version: :draft6 } end |
Instance Method Details
#http_method ⇒ Object
17 18 19 |
# File 'lib/vbs/requests/base.rb', line 17 def http_method self.class::HTTP_METHOD end |
#path ⇒ Object
21 22 23 |
# File 'lib/vbs/requests/base.rb', line 21 def path self.class::PATH end |
#valid? ⇒ Boolean
35 36 37 38 39 40 41 42 43 |
# File 'lib/vbs/requests/base.rb', line 35 def valid? begin validate! rescue VBS::Requests::InvalidRequestError return false end true end |
#validate! ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/vbs/requests/base.rb', line 25 def validate! validate_request_model! @errors = JSON::Validator.fully_validate(self.class.schema, data, self.class.) raise VBS::Requests::InvalidRequestError, errors if @errors.any? self end |
#validate_request_model! ⇒ Object (private)
47 48 49 50 51 |
# File 'lib/vbs/requests/base.rb', line 47 def validate_request_model! raise "#{self.class.name}::HTTP_METHOD is not defined" unless self.class.const_defined?(:HTTP_METHOD) raise "#{self.class.name}::PATH not defined" unless self.class.const_defined?(:PATH) raise "#{self.class.name}::schema is not defined " unless defined?(self.class.schema) end |