Module: Hydra::RemoteIdentifier

Defined in:
lib/hydra/remote_identifier/mapper.rb,
lib/hydra/remote_identifier/minter.rb,
lib/hydra/remote_identifier/railtie.rb,
lib/hydra/remote_identifier/version.rb,
lib/hydra/remote_identifier/exceptions.rb,
lib/hydra/remote_identifier/registration.rb,
lib/hydra/remote_identifier/configuration.rb,
lib/hydra/remote_identifier/remote_service.rb,
lib/hydra/remote_identifier/minting_coordinator.rb,
lib/hydra/remote_identifier/remote_services/doi.rb,
lib/hydra/remote_identifier.rb

Defined Under Namespace

Modules: RemoteServices Classes: Configuration, DoiGenerator, InstallGenerator, InvalidServiceMapping, Mapper, Minter, MintingCoordinator, Railtie, Registration, RemoteService, RemoteServiceError

Constant Summary collapse

VERSION =
"0.6.7"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



38
39
40
# File 'lib/hydra/remote_identifier.rb', line 38

def configuration
  @configuration
end

Class Method Details

.configure {|config| ... } ⇒ Object

Used for configuring available RemoteService and any additional initialization requirements for those RemoteServices (i.e. credentials)

Examples:

Hydra::RemoteIdentifier.configure do |config|
  config.remote_service(:doi, doi_credentials) do |doi|
    doi.register(target_class) do |map|
      map.target :url
      map.creator :creator
      map.title :title
      map.publisher :publisher
      map.publicationyear :publicationyear
      map.set_identifier(:set_identifier=)
    end
  end
end

Yield Parameters:

See Also:



30
31
32
33
34
35
36
37
# File 'lib/hydra/remote_identifier.rb', line 30

def configure(&block)
  @configuration_block = block

  # The Rails load sequence means that some of the configured Targets may
  # not be loaded; As such I am not calling configure! instead relying on
  # Hydra::RemoteIdentifier::Railtie to handle the configure! call
  configure! unless defined?(Rails)
end

.configure!Object



40
41
42
43
44
45
# File 'lib/hydra/remote_identifier.rb', line 40

def configure!
  if @configuration_block.respond_to?(:call)
    self.configuration ||= Configuration.new
    @configuration_block.call(configuration)
  end
end

.mint(remote_service_name, target) ⇒ Object

Using the RemoteService mint the corresponding remote identifier for the target. You must first configure the RemoteService and target’s class to define the attribute map. See Hydra::RemoteIdentifier.configure

Examples:

Hydra::RemoteIdentifier.mint(:doi, book)

Parameters:

  • remote_service_name (#to_s)
  • target (#registered_remote_identifier_minters)


132
133
134
135
136
# File 'lib/hydra/remote_identifier.rb', line 132

def mint(remote_service_name, target)
  registered?(remote_service_name, target) do |remote_service, coordinator|
    coordinator.call(target)
  end
end

.registered?(remote_service_name, target) {|@required, @optional| ... } ⇒ Boolean Also known as: with_registered_remote_service

Yields the specified RemoteService if it could be requested for the Target.

Examples:

<% Hydra::RemoteIdentifier.registered?(:doi, book) do |remote_service| %>
  <%= f.input remote_service.accessor_name %>
<% end %>

Parameters:

  • remote_service_name (#to_s)
  • target (#registered_remote_identifier_minters)

Yield Parameters:

  • @required

    first [RemoteService]

  • @optional

    second [MintingCoordinator]

Returns:

  • (Boolean)


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/hydra/remote_identifier.rb', line 73

def registered?(remote_service_name, target, &block)
  return false unless target.respond_to?(:registered_remote_identifier_minters)
  !!target.registered_remote_identifier_minters.detect do |coordinator|
    # require 'debugger'; debugger; true;
    if coordinator.remote_service.to_s == remote_service_name.to_s
      if block_given?
        if block.arity == 2
          block.call(coordinator.remote_service, coordinator)
        else
          block.call(coordinator.remote_service)
        end
      end
      true
    end
  end
end

.remote_service(remote_service_name) ⇒ Object

Retrieve a valid RemoteService by name

Examples:

doi_remote_service = Hydra::RemoteIdentifier.remote_service(:doi)

Parameters:

  • remote_service_name (#to_s)


54
55
56
# File 'lib/hydra/remote_identifier.rb', line 54

def remote_service(remote_service_name)
  configuration.find_remote_service(remote_service_name)
end

.remote_uri_for(remote_service_name, identifier) ⇒ Object

Examples:

<%= link_to(object.doi, Hydra::RemoteIdentifier.remote_uri_for(:doi, object.doi)) %>

Parameters:

  • remote_service_name (#to_s)
  • identifier (#to_s)
    • An identifier that was created by the

    RemoteService derived from the given remote_service_name



99
100
101
102
# File 'lib/hydra/remote_identifier.rb', line 99

def remote_uri_for(remote_service_name, identifier)
  remote_service = configuration.find_remote_service(remote_service_name)
  remote_service.remote_uri_for(identifier)
end

.requested_remote_identifiers_for(target) ⇒ Object

Yields each RemoteService#name that is requested for the Target.

Examples:

Hydra::RemoteIdentifier.requested_remote_identifiers_for(book) do |remote_service_name|
  Hydra::RemoteIdentifier.mint(remote_service_name, book)
end

Parameters:

  • target (#registered_remote_identifier_minters)


113
114
115
116
117
118
119
120
121
# File 'lib/hydra/remote_identifier.rb', line 113

def requested_remote_identifiers_for(target)
  return false unless target.respond_to?(:registered_remote_identifier_minters)
  target.registered_remote_identifier_minters.each do |coordinator|
    remote_service = coordinator.remote_service
    if target.public_send(remote_service.accessor_name).to_i != 0
      yield(remote_service)
    end
  end
end