cirneco 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a761311be0485a9712ca2f2dc30c3dec2c44ca0
4
- data.tar.gz: ba477ef68eeffa7bf27e014131407714de8f3c1c
3
+ metadata.gz: eaeaad21cf2a466a9c9cd5f263c3023ffbb06d88
4
+ data.tar.gz: e8a4c0677b9c1b295b08df6cfba35059c245836f
5
5
  SHA512:
6
- metadata.gz: c19efc867ab3112914ea0af11c2d5fc693d25b4e630c1300318df8988b260451185a65ecf23161b2cfc39f4b9d3111e926af89e2b80f9ffd3a9704037db060c2
7
- data.tar.gz: 3d7d4d63127f7600c5fa50244235be60ce4a0b311913ce985de141a7a932b06e7bc461e32df814ff1ebf15a00bbc281a30f44da4bd0fab82ff1cf7edfff7d5dd
6
+ metadata.gz: c77a6e9d70d11a4452b7ae5d8167fba20aaeaedfbced8b79008f2b0c4fbe8d1e77095b20198b51b25c756a0a01478cd90a5a607b147415ba8876d48940f42fdd
7
+ data.tar.gz: 8e995c12b58effd10dea51965c8d2874f1bf925cb4ccf95d033f646b424ccc99ebdb6001522847ce991c70316a6d2d18604ecec4849b7d74b7983340678db5fb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cirneco (0.6.1)
4
+ cirneco (0.6.2)
5
5
  activesupport (~> 4.2, >= 4.2.5)
6
6
  base32-crockford-checksum (~> 0.2.2)
7
7
  bergamasco (~> 0.2)
@@ -22,7 +22,7 @@ GEM
22
22
  tzinfo (~> 1.1)
23
23
  addressable (2.3.8)
24
24
  base32-crockford-checksum (0.2.3)
25
- bergamasco (0.2.11)
25
+ bergamasco (0.2.12)
26
26
  activesupport (~> 4.2, >= 4.2.5)
27
27
  addressable (~> 2.3.8)
28
28
  builder (~> 3.2, >= 3.2.2)
@@ -127,4 +127,4 @@ DEPENDENCIES
127
127
  webmock (~> 1.22, >= 1.22.3)
128
128
 
129
129
  BUNDLED WITH
130
- 1.13.6
130
+ 1.12.5
data/lib/cirneco/doi.rb CHANGED
@@ -48,32 +48,32 @@ module Cirneco
48
48
  end
49
49
  end
50
50
 
51
- desc "register DOCUMENTS", "register documents"
51
+ desc "mint DOCUMENTS", "mint documents"
52
52
  method_option :username, :default => ENV['MDS_USERNAME']
53
53
  method_option :password, :default => ENV['MDS_PASSWORD']
54
54
  method_option :prefix, :default => ENV['PREFIX']
55
55
  method_option :sandbox, :default => ENV['SANDBOX']
56
- def register(filepath)
56
+ def mint(filepath)
57
57
 
58
58
  if File.directory?(filepath)
59
- response = register_all_files(filepath, options)
59
+ response = mint_dois_for_all_files(filepath, options)
60
60
  else
61
- response = register_file(filepath, options)
61
+ response = mint_doi_for_file(filepath, options)
62
62
  end
63
63
 
64
64
  puts response
65
65
  end
66
66
 
67
- desc "unregister DOCUMENTS", "unregister documents"
67
+ desc "hide DOCUMENTS", "hide documents"
68
68
  method_option :username, :default => ENV['MDS_USERNAME']
69
69
  method_option :password, :default => ENV['MDS_PASSWORD']
70
70
  method_option :sandbox, :default => ENV['SANDBOX']
71
- def unregister(filepath)
71
+ def hide(filepath)
72
72
 
73
73
  if File.directory?(filepath)
74
- response = unregister_all_files(filepath, options)
74
+ response = hide_dois_for_all_files(filepath, options)
75
75
  else
76
- response = unregister_file(filepath, options)
76
+ response = hide_doi_for_file(filepath, options)
77
77
  end
78
78
 
79
79
  puts response
data/lib/cirneco/utils.rb CHANGED
@@ -28,12 +28,12 @@ module Cirneco
28
28
  end
29
29
 
30
30
  # currently only supports markdown files with YAML header
31
- def register_file(filepath, options={})
31
+ def mint_doi_for_file(filepath, options={})
32
32
  filename = File.basename(filepath)
33
33
  return "File #{filename} ignored: not a markdown file" unless File.extname(filepath) == ".md"
34
34
 
35
35
  old_metadata = Bergamasco::Markdown.read_yaml_for_doi_metadata(filepath)
36
- return nil if old_metadata["doi"]
36
+ return nil if old_metadata["doi"] && old_metadata["published"]
37
37
 
38
38
  metadata = generate_metadata_for_work(filepath, options)
39
39
  work = register_work_for_metadata(metadata)
@@ -44,17 +44,18 @@ module Cirneco
44
44
  # new_data = [{ "filename" => filename, "doi" => doi, "date" => Time.now.utc.iso8601 }]
45
45
  # Bergamasco::Markdown.write_yaml(datapath, data + new_data)
46
46
 
47
- new_metadata = Bergamasco::Markdown.update_file(filepath, { "doi" => metadata["doi"] })
48
- "DOI #{new_metadata["doi"]} added for #{filename}"
47
+ new_metadata = Bergamasco::Markdown.update_file(filepath, "doi" => metadata["doi"], "published" => true)
48
+ "DOI #{new_metadata["doi"]} minted for #{filename}"
49
49
  end
50
50
 
51
51
  # currently only supports markdown files with YAML header
52
- def unregister_file(filepath, options={})
52
+ # DOIs are never deleted, but we can remove the metadata from the DataCite index
53
+ def hide_doi_for_file(filepath, options={})
53
54
  filename = File.basename(filepath)
54
55
  return "File #{filename} ignored: not a markdown file" unless File.extname(filepath) == ".md"
55
56
 
56
57
  old_metadata = Bergamasco::Markdown.read_yaml_for_doi_metadata(filepath)
57
- return nil unless old_metadata["doi"]
58
+ return nil unless old_metadata["doi"] && old_metadata["published"]
58
59
 
59
60
  metadata = generate_metadata_for_work(filepath, options)
60
61
  work = unregister_work_for_metadata(metadata)
@@ -65,19 +66,19 @@ module Cirneco
65
66
  # new_data = [{ "filename" => filename, "doi" => doi, "date" => Time.now.utc.iso8601 }]
66
67
  # Bergamasco::Markdown.write_yaml(datapath, data + new_data)
67
68
 
68
- new_metadata = Bergamasco::Markdown.update_file(filepath, { "doi" => nil })
69
- "DOI #{old_metadata["doi"]} removed for #{filename}"
69
+ new_metadata = Bergamasco::Markdown.update_file(filepath, "published" => false)
70
+ "DOI #{old_metadata["doi"]} hidden for #{filename}"
70
71
  end
71
72
 
72
- def register_all_files(folderpath, options={})
73
+ def mint_dois_for_all_files(folderpath, options={})
73
74
  Dir.glob("#{folderpath}/*.md").map do |filepath|
74
- register_file(filepath, options)
75
+ mint_doi_for_file(filepath, options)
75
76
  end.compact.join("\n")
76
77
  end
77
78
 
78
- def unregister_all_files(folderpath, options={})
79
+ def hide_dois_for_all_files(folderpath, options={})
79
80
  Dir.glob("#{folderpath}/*.md").map do |filepath|
80
- unregister_file(filepath, options)
81
+ hide_doi_for_file(filepath, options)
81
82
  end.compact.join("\n")
82
83
  end
83
84
 
@@ -201,7 +202,7 @@ module Cirneco
201
202
  work = Cirneco::Work.new(metadata)
202
203
 
203
204
  filename = metadata["doi"].split("/", 2).last + ".xml"
204
- File.delete(filename)
205
+ File.delete(filename) if File.exist?(filename)
205
206
 
206
207
  work
207
208
  end
@@ -1,3 +1,3 @@
1
1
  module Cirneco
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2"
3
3
  end
@@ -7,6 +7,8 @@ tags:
7
7
  - doi
8
8
  - featured
9
9
  image: https://blog.datacite.org/images/2016/12/cool-dois.png
10
+ doi: 10.23725/0000-03VC
11
+ published: false
10
12
  ---
11
13
  In 1998 Tim Berners-Lee coined the term cool URIs [-@https://www.w3.org/Provider/Style/URI], that is URIs that don’t change. We know that URLs referenced in the scholarly literature are often not cool, leading to link rot [@https://doi.org/10.1371/journal.pone.0115253] and making it hard or impossible to find the referenced resource.READMORE
12
14
 
data/spec/utils_spec.rb CHANGED
@@ -40,35 +40,41 @@ describe Cirneco::DataCenter, vcr: true, :order => :defined do
40
40
  end
41
41
  end
42
42
 
43
- describe "register" do
44
- it 'should register_file' do
43
+ describe "mint and hide DOIs" do
44
+ it 'should mint for file' do
45
45
  filepath = fixture_path + 'cool-dois.html.md'
46
46
  number = 123
47
- response = subject.register_file(filepath, number: number)
48
- expect(response).to eq("DOI 10.23725/0000-03VC added for cool-dois.html.md")
47
+ response = subject.mint_doi_for_file(filepath, number: number)
48
+ expect(response).to eq("DOI 10.23725/0000-03VC minted for cool-dois.html.md")
49
49
  end
50
50
 
51
- it 'should unregister_file' do
51
+ it 'should hide for file' do
52
52
  filepath = fixture_path + 'cool-dois.html.md'
53
- response = subject.unregister_file(filepath)
54
- expect(response).to eq("DOI 10.23725/0000-03VC removed for cool-dois.html.md")
53
+ response = subject.hide_doi_for_file(filepath)
54
+ expect(response).to eq("DOI 10.23725/0000-03VC hidden for cool-dois.html.md")
55
55
  end
56
56
 
57
- it 'should register_all_files' do
57
+ it 'should mint for all files' do
58
58
  number = 123
59
- response = subject.register_all_files(fixture_path, number: number)
60
- expect(response).to eq("DOI 10.23725/0000-03VC added for cool-dois.html.md")
59
+ response = subject.mint_dois_for_all_files(fixture_path, number: number)
60
+ expect(response).to eq("DOI 10.23725/0000-03VC minted for cool-dois.html.md")
61
61
  end
62
62
 
63
- it 'should unregister_all_files' do
63
+ it 'should hide for all files' do
64
64
  number = 123
65
- response = subject.unregister_all_files(fixture_path)
66
- expect(response).to eq("DOI 10.23725/0000-03VC removed for cool-dois.html.md")
65
+ response = subject.hide_dois_for_all_files(fixture_path)
66
+ expect(response).to eq("DOI 10.23725/0000-03VC hidden for cool-dois.html.md")
67
67
  end
68
68
 
69
- it 'should ignore non-markdown file for register_file' do
69
+ it 'should ignore non-markdown file for mint file' do
70
70
  filepath = fixture_path + 'cool-dois.yml'
71
- response = subject.register_file(filepath)
71
+ response = subject.mint_doi_for_file(filepath)
72
+ expect(response).to eq("File cool-dois.yml ignored: not a markdown file")
73
+ end
74
+
75
+ it 'should ignore non-markdown file for hide file' do
76
+ filepath = fixture_path + 'cool-dois.yml'
77
+ response = subject.hide_doi_for_file(filepath)
72
78
  expect(response).to eq("File cool-dois.yml ignored: not a markdown file")
73
79
  end
74
80
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cirneco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner