Class: ElocalApiSupport::Authorization::DefaultAuthorizer
- Inherits:
-
Object
- Object
- ElocalApiSupport::Authorization::DefaultAuthorizer
- Defined in:
- lib/elocal_api_support/default_authorizer.rb
Constant Summary collapse
- FAIL_MESSAGE =
<<-EOL.strip No token could be found for ElocalApiSupport to use. Please resolve this by either - Define a method required_token which provides a token to check - Set the configuration token in your config/application.rb by setting a value for config.elocal_api_support_token - Define a method authorizer return a custom Authorization object which responds to authorize(token) EOL
Instance Attribute Summary collapse
-
#caller ⇒ Object
readonly
Returns the value of attribute caller.
Instance Method Summary collapse
- #authorize(token) ⇒ Object
- #find_required_token ⇒ Object
-
#initialize(caller) ⇒ DefaultAuthorizer
constructor
A new instance of DefaultAuthorizer.
Constructor Details
#initialize(caller) ⇒ DefaultAuthorizer
Returns a new instance of DefaultAuthorizer.
12 13 14 |
# File 'lib/elocal_api_support/default_authorizer.rb', line 12 def initialize(caller) @caller = caller end |
Instance Attribute Details
#caller ⇒ Object (readonly)
Returns the value of attribute caller.
3 4 5 |
# File 'lib/elocal_api_support/default_authorizer.rb', line 3 def caller @caller end |
Instance Method Details
#authorize(token) ⇒ Object
16 17 18 |
# File 'lib/elocal_api_support/default_authorizer.rb', line 16 def (token) find_required_token == token end |
#find_required_token ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/elocal_api_support/default_authorizer.rb', line 20 def find_required_token if caller.respond_to?(:required_token, true) caller.send(:required_token) elsif Rails.application.config.elocal_api_support_token.present? Rails.application.config.elocal_api_support_token else fail FAIL_MESSAGE end end |