Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rails_api_authentication
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
rails_api_authentication
Commits
de99506d
Commit
de99506d
authored
May 02, 2017
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add load_available_adapters method
parent
38a6dda4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
rails_api_authentication.rb
lib/rails_api_authentication.rb
+35
-0
configuration.rb
lib/rails_api_authentication/configuration.rb
+2
-0
No files found.
lib/rails_api_authentication.rb
View file @
de99506d
...
...
@@ -24,6 +24,41 @@ module RailsApiAuthentication
end
end
# Private: Load the available adapters.
#
# adapters_short_names - Array of names of the adapters to load if available
#
# Example
#
# load_available_adapters ['unavailable_adapter', 'available_adapter']
# # => [RailsApiAuthentication::Adapters::AvailableAdapter]
#
# Returns an Array of available adapters
def
self
.
load_available_adapters
adapters_short_names
available_adapters
=
adapters_short_names
.
collect
do
|
short_name
|
next
if
short_name
==
'rails'
&&
(
ActiveSupport
.
respond_to?
(
:version
)
&&
ActiveSupport
.
version
>=
Gem
::
Version
.
new
(
'4.1.0'
))
next
if
short_name
==
'rails_api'
&&
(
ActiveSupport
.
respond_to?
(
:version
)
&&
ActiveSupport
.
version
>=
Gem
::
Version
.
new
(
'5.0.0'
))
adapter_name
=
"rails_api_authentication/adapters/
#{
short_name
}
_adapter"
if
adapter_dependency_fulfilled?
(
short_name
)
&&
require
(
adapter_name
)
adapter_name
.
camelize
.
constantize
end
end
available_adapters
.
compact!
available_adapters
end
def
self
.
adapter_dependency_fulfilled?
adapter_short_name
dependency
=
RailsApiAuthentication
.
adapters_dependencies
[
adapter_short_name
]
if
!
respond_to?
(
:qualified_const_defined?
)
||
(
ActiveSupport
.
respond_to?
(
:version
)
&&
ActiveSupport
.
version
.
to_s
=~
/^5\.0/
)
# See https://github.com/gonzalo-bulnes/simple_token_authentication/pull/229/commits/74eda6c28cd0b45636c466de56f2dbaca5c5b629#r57507423
const_defined?
(
dependency
)
else
qualified_const_defined?
(
dependency
)
end
end
available_model_adapters
=
load_available_adapters
RailsApiAuthentication
.
model_adapters
ensure_models_can_act_as_token_authenticatables
available_model_adapters
...
...
lib/rails_api_authentication/configuration.rb
View file @
de99506d
...
...
@@ -2,7 +2,9 @@ module RailsApiAuthentication
module
Configuration
mattr_accessor
:controller_adapters
mattr_accessor
:model_adapters
mattr_accessor
:adapters_dependencies
@@controller_adapters
=
[
'rails'
,
'rails_api'
,
'rails_metal'
]
@@model_adapters
=
[
'active_record'
,
'mongoid'
]
@@adapters_dependencies
=
{
'active_record'
=>
'ActiveRecord::Base'
,
'mongoid'
=>
'Mongoid::Document'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment