Class: Orcid::ProfileStatus
- Inherits:
-
Object
- Object
- Orcid::ProfileStatus
- Defined in:
- app/models/orcid/profile_status.rb
Overview
Responsible for determining a given user’s orcid profile state as it pertains to the parent application.
- has leaked out (i.e. the Orcid::ProfileConnectionsController and Orcid
-
ProfileRequestsController)
ProfileStatus.status :authenticated_connection - User has authenticated against the Orcid
remote system
:pending_connection - User has indicated there is a connection, but has
not authenticated against the Orcid remote system
:profile_request_pending - User has requested a profile be created on
their behalf
:unknown - None of the above
Instance Attribute Summary collapse
-
#callback_handler ⇒ Object
readonly
Returns the value of attribute callback_handler.
-
#profile_finder ⇒ Object
readonly
Returns the value of attribute profile_finder.
-
#request_finder ⇒ Object
readonly
Returns the value of attribute request_finder.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(user, collaborators = {}) {|callback_handler| ... } ⇒ ProfileStatus
constructor
A new instance of ProfileStatus.
- #status ⇒ Object
Constructor Details
#initialize(user, collaborators = {}) {|callback_handler| ... } ⇒ ProfileStatus
Returns a new instance of ProfileStatus.
24 25 26 27 28 29 30 |
# File 'app/models/orcid/profile_status.rb', line 24 def initialize(user, collaborators = {}) @user = user @profile_finder = collaborators.fetch(:profile_finder) { default_profile_finder } @request_finder = collaborators.fetch(:request_finder) { default_request_finder } @callback_handler = collaborators.fetch(:callback_handler) { default_callback_handler } yield(callback_handler) if block_given? end |
Instance Attribute Details
#callback_handler ⇒ Object (readonly)
Returns the value of attribute callback_handler.
22 23 24 |
# File 'app/models/orcid/profile_status.rb', line 22 def callback_handler @callback_handler end |
#profile_finder ⇒ Object (readonly)
Returns the value of attribute profile_finder.
22 23 24 |
# File 'app/models/orcid/profile_status.rb', line 22 def profile_finder @profile_finder end |
#request_finder ⇒ Object (readonly)
Returns the value of attribute request_finder.
22 23 24 |
# File 'app/models/orcid/profile_status.rb', line 22 def request_finder @request_finder end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
22 23 24 |
# File 'app/models/orcid/profile_status.rb', line 22 def user @user end |
Class Method Details
.for(user, collaborators = {}, &block) ⇒ Object
18 19 20 |
# File 'app/models/orcid/profile_status.rb', line 18 def self.for(user, collaborators = {}, &block) new(user, collaborators, &block).status end |
Instance Method Details
#status ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/models/orcid/profile_status.rb', line 32 def status return callback(:unknown) if user.nil? profile = profile_finder.call(user) if profile if profile.verified_authentication? return callback(:authenticated_connection, profile) else return callback(:pending_connection, profile) end else request = request_finder.call(user) if request if request.error_on_profile_creation? return callback(:profile_request_in_error, request) else return callback(:profile_request_pending, request) end else return callback(:unknown) end end end |