Class: OpenStax::Api::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/openstax_api.rb

Overview

Configuration machinery.

To configure OpenStax Api, put the following code in your applications initialization logic (eg. in the config/initializers in a Rails app)

OpenStax::Api.configure do |config|
  config.<parameter name> = <parameter value>
  ...
end

user_class_name is a String containing the name of your User model class.

current_user_method is a String containing the name of your controller method that returns the current user.

routing_error_app is a Rack application that responds to routing errors for the API

validate_cors_origin is a Proc that is called with the reqested origin for CORS requests. The proc should return true/false to indicate the validity of the request’s origin

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



44
45
46
47
48
49
# File 'lib/openstax_api.rb', line 44

def initialize
  @user_class_name = 'User'
  @current_user_method = 'current_user'
  @routing_error_app = lambda { |env|
    [404, {"Content-Type" => 'application/json'}, ['']] }
end

Instance Attribute Details

#current_user_methodObject

Returns the value of attribute current_user_method.



40
41
42
# File 'lib/openstax_api.rb', line 40

def current_user_method
  @current_user_method
end

#routing_error_appObject

Returns the value of attribute routing_error_app.



41
42
43
# File 'lib/openstax_api.rb', line 41

def routing_error_app
  @routing_error_app
end

#user_class_nameObject

Returns the value of attribute user_class_name.



39
40
41
# File 'lib/openstax_api.rb', line 39

def user_class_name
  @user_class_name
end

#validate_cors_originObject

Returns the value of attribute validate_cors_origin.



42
43
44
# File 'lib/openstax_api.rb', line 42

def validate_cors_origin
  @validate_cors_origin
end