Class: Hydra::RemoteIdentifier::DoiGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/hydra/remote_identifier/doi_generator.rb

Constant Summary collapse

DEFAULT_CREDENTIALS_PATH =
'config/doi.yml'

Instance Method Summary collapse

Instance Method Details

#insert_doiObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/generators/hydra/remote_identifier/doi_generator.rb', line 16

def insert_doi

  inject_into_file(
    "config/initializers/hydra-remote_identifier_config.rb",
    after: /Hydra::RemoteIdentifier.*/
  ) do

    data = []
    data << ""
    data << %(  doi_credentials = Psych.load_file(Rails.root.join("#{credentials_path}")))
    data << %(  config.remote_service(:doi, doi_credentials) do |doi|)
    data << %(    doi.register(#{normalized_targets}) do |map|)
    data << %(      map.target #{options.fetch('target')})
    data << %(      map.creator #{options.fetch('creator')})
    data << %(      map.title #{options.fetch('title')})
    data << %(      map.publisher #{options.fetch('publisher')})
    data << %(      map.publicationyear #{options.fetch('publication_year')})
    data << %(      # Make sure that this method both sets the identifier and persists the change!)
    data << %(      map.set_identifier #{options.fetch('set_identifier')})
    data << %(    end)
    data << %(  end)
    data << ""
    data.join("\n")

  end
end

#optionally_create_credentials_pathObject



43
44
45
46
47
48
49
50
51
# File 'lib/generators/hydra/remote_identifier/doi_generator.rb', line 43

def optionally_create_credentials_path
  if credentials_path == DEFAULT_CREDENTIALS_PATH
    require 'hydra/remote_identifier/remote_services/doi'
    create_file(
      credentials_path,
      Hydra::RemoteIdentifier::RemoteServices::Doi::TEST_CONFIGURATION.to_yaml
    )
  end
end