Module: Hydra::RemoteIdentifier

Defined in:
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/railtie.rb,
lib/hydra/remote_identifier/minter.rb,
lib/hydra/remote_identifier/mapper.rb,
lib/hydra/remote_identifier.rb

Defined Under Namespace

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

Constant Summary collapse

VERSION =
"0.5.0"

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)


109
110
111
112
113
114
115
116
117
# File 'lib/hydra/remote_identifier.rb', line 109

def mint(remote_service_name, target)
  return false unless target.respond_to?(:registered_remote_identifier_minters)

  # @TODO - there is a better way to do this but this is "complete/correct"
  remote_service = configuration.find_remote_service(remote_service_name)
  target.registered_remote_identifier_minters.each do |coordinator|
    coordinator.call(target) if coordinator.remote_service == remote_service
  end
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



76
77
78
79
# File 'lib/hydra/remote_identifier.rb', line 76

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)


90
91
92
93
94
95
96
97
98
# File 'lib/hydra/remote_identifier.rb', line 90

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

.with_registered_remote_service(remote_service_name, target) ⇒ Object

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

Examples:

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

Parameters:

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


58
59
60
61
62
63
64
65
66
67
# File 'lib/hydra/remote_identifier.rb', line 58

def with_registered_remote_service(remote_service_name, target)
  return false unless target.respond_to?(:registered_remote_identifier_minters)
  # @TODO - the registered remote identifier is more than a bit off;
  # but it continues to work
  target.registered_remote_identifier_minters.each {|coordinator|
    if coordinator.remote_service.name.to_s == remote_service_name.to_s
      yield(coordinator.remote_service)
    end
  }
end