module Grape::OAuth2::Configuration::Validation

Validates Grape::OAuth2 configuration.

Constants

REQUIRED_CLASSES_API

API mapping. Classes, that represents OAuth2 roles, must have described methods.

Public Instance Methods

check!() click to toggle source

Checks configuration to be set correctly (required classes must be defined and implement specific set of API).

# File lib/grape_oauth2/configuration/validation.rb, line 8
def check!
  check_required_classes!
  check_required_classes_api!
end

Private Instance Methods

check_class_methods(klass, required_methods) click to toggle source

Validates that required classes have required class methods.

# File lib/grape_oauth2/configuration/validation.rb, line 53
def check_class_methods(klass, required_methods)
  (required_methods || []).each do |method|
    method_exist = send(klass).respond_to?(method)
    raise APIMissing, "Class method '#{method}' must be defined for the '#{klass}'!" unless method_exist
  end
end
check_instance_methods(klass, required_methods) click to toggle source

Validates that required classes have required instance methods.

# File lib/grape_oauth2/configuration/validation.rb, line 61
def check_instance_methods(klass, required_methods)
  (required_methods || []).each do |method|
    unless send(klass).method_defined?(method)
      raise APIMissing, "Instance method '#{method}' must be defined for the '#{klass}'!"
    end
  end
end
check_required_classes!() click to toggle source

Validates that required classes defined.

# File lib/grape_oauth2/configuration/validation.rb, line 34
def check_required_classes!
  REQUIRED_CLASSES_API.keys.each do |klass|
    begin
      object = send(klass)
    rescue NoMethodError
      raise Error, "'#{klass}' must be defined!" if object.nil? || !defined?(object)
    end
  end
end
check_required_classes_api!() click to toggle source

Validates that required classes have all the API.

# File lib/grape_oauth2/configuration/validation.rb, line 45
def check_required_classes_api!
  REQUIRED_CLASSES_API.each do |klass, api_methods|
    check_class_methods(klass, api_methods[:class_methods])
    check_instance_methods(klass, api_methods[:instance_methods])
  end
end