Class: VBS::Requests::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/vbs/requests/base.rb

Direct Known Subclasses

ListStatements

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorsObject (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_optionsObject



10
11
12
13
14
15
# File 'lib/vbs/requests/base.rb', line 10

def self.schema_validation_options
  {
    errors_as_objects: true,
    version: :draft6
  }
end

Instance Method Details

#http_methodObject



17
18
19
# File 'lib/vbs/requests/base.rb', line 17

def http_method
  self.class::HTTP_METHOD
end

#pathObject



21
22
23
# File 'lib/vbs/requests/base.rb', line 21

def path
  self.class::PATH
end

#valid?Boolean

Returns:

  • (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.schema_validation_options)

  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