Class: Orcid::ProfileStatus

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, collaborators = {}) {|callback_handler| ... } ⇒ ProfileStatus

Returns a new instance of ProfileStatus.

Yields:



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_handlerObject (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_finderObject (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_finderObject (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

#userObject (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

#statusObject



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