Class: Orcid::ProfileConnection

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::Validations
Defined in:
app/models/orcid/profile_connection.rb

Overview

Responsible for connecting an authenticated user to the ORCID profile that the user searched for and selected.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#orcid_profile_candidatesObject



65
66
67
# File 'app/models/orcid/profile_connection.rb', line 65

def orcid_profile_candidates
  @orcid_profile_candidates || lookup_profile_candidates
end

#persister=(value) ⇒ Object

Sets the attribute persister

Parameters:

  • value

    the value to set the attribute persister to.



34
35
36
# File 'app/models/orcid/profile_connection.rb', line 34

def persister=(value)
  @persister = value
end

#profile_query_service=(value) ⇒ Object

Sets the attribute profile_query_service

Parameters:

  • value

    the value to set the attribute profile_query_service to.



45
46
47
# File 'app/models/orcid/profile_connection.rb', line 45

def profile_query_service=(value)
  @profile_query_service = value
end

Instance Method Details

#default_persisterObject



40
41
42
43
# File 'app/models/orcid/profile_connection.rb', line 40

def default_persister
  require 'orcid'
  Orcid.method(:connect_user_and_orcid_profile)
end

#persisted?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/models/orcid/profile_connection.rb', line 30

def persisted?
  false
end

#query_attributesObject



81
82
83
84
85
86
87
# File 'app/models/orcid/profile_connection.rb', line 81

def query_attributes
  available_query_attribute_names.each_with_object({}) do |name, mem|
    orcid_formatted_name = convert_attribute_name_to_orcid_format(name)
    mem[orcid_formatted_name] = attributes.fetch(name)
    mem
  end
end

#saveObject



26
27
28
# File 'app/models/orcid/profile_connection.rb', line 26

def save
  valid? ? persister.call(user, orcid_profile_id) : false
end

#with_orcid_profile_candidates {|orcid_profile_candidates| ... } ⇒ Object



59
60
61
# File 'app/models/orcid/profile_connection.rb', line 59

def with_orcid_profile_candidates
  yield(orcid_profile_candidates) if query_requested?
end