module GrapeTokenAuth::MountHelpers::ClassMethods
Attributes
resource_scope[R]
Public Instance Methods
mount_confirmation(opts = {})
click to toggle source
# File lib/grape_token_auth/mount_helpers.rb, line 17 def mount_confirmation(opts = {}) mount_api('ConfirmationAPI', set_mount_point(opts, '/confirmation')) end
mount_omniauth(opts = {})
click to toggle source
# File lib/grape_token_auth/mount_helpers.rb, line 29 def mount_omniauth(opts = {}) path = opts.fetch(:to, '/') if opts.key?(:for) api = create_api_subclass('OmniAuthAPI', opts[:for]) else api = GrapeTokenAuth::OmniAuthAPI end mount api => path end
mount_omniauth_callbacks(opts = {})
click to toggle source
# File lib/grape_token_auth/mount_helpers.rb, line 41 def mount_omniauth_callbacks(opts = {}) fail 'Oauth callback API is not scope specific. Only mount it once and do not pass a "for" option' if opts[:for] fail 'Oauth callback API path is specificed in the configuration. Do not pass a "to" option' if opts[:to] prefix = GrapeTokenAuth.set_omniauth_path_prefix! mount GrapeTokenAuth::OmniAuthCallBackRouterAPI => prefix end
mount_password_reset(opts = {})
click to toggle source
# File lib/grape_token_auth/mount_helpers.rb, line 25 def mount_password_reset(opts = {}) mount_api('PasswordAPI', set_mount_point(opts, '/password')) end
mount_registration(opts = {})
click to toggle source
# File lib/grape_token_auth/mount_helpers.rb, line 9 def mount_registration(opts = {}) mount_api('RegistrationAPI', opts) end
mount_sessions(opts = {})
click to toggle source
# File lib/grape_token_auth/mount_helpers.rb, line 13 def mount_sessions(opts = {}) mount_api('SessionsAPI', opts) end
mount_token_validation(opts = {})
click to toggle source
# File lib/grape_token_auth/mount_helpers.rb, line 21 def mount_token_validation(opts = {}) mount_api('TokenValidationAPI', opts) end
Private Instance Methods
create_api_subclass(class_name, mapping)
click to toggle source
# File lib/grape_token_auth/mount_helpers.rb, line 67 def create_api_subclass(class_name, mapping) resource_class = GrapeTokenAuth.configuration.scope_to_class(mapping) fail ScopeUndefinedError.new(nil, mapping) unless resource_class scope_name = Utility.humanize(mapping) api = create_grape_api api.instance_variable_set(:@resource_scope, mapping) api.include(GrapeTokenAuth.const_get("#{class_name}Core")) GrapeTokenAuth.const_set("#{scope_name}#{class_name}", api) end
create_grape_api()
click to toggle source
# File lib/grape_token_auth/mount_helpers.rb, line 77 def create_grape_api Class.new(Grape::API) do class << self attr_reader :resource_scope end end end
mount_api(api_class_name, opts)
click to toggle source
# File lib/grape_token_auth/mount_helpers.rb, line 55 def mount_api(api_class_name, opts) path = opts.fetch(:to, '/') if opts.key?(:for) api = create_api_subclass(api_class_name, opts[:for]) else api = GrapeTokenAuth.const_get(api_class_name) end mount api => path end
set_mount_point(opts, route)
click to toggle source
# File lib/grape_token_auth/mount_helpers.rb, line 50 def set_mount_point(opts, route) opts[:to] = "#{opts[:to].to_s.chomp('/')}#{route}" opts end