active_fedora-noid 0.3.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ccbc2239b7c60748fb0fde64de2810dae5bc1ec
4
- data.tar.gz: c76dd79fe28f8d2304f7d9e2e167b286a3a9a07d
3
+ metadata.gz: c19bc92adee3e3f65792c9c8a3d06fff8c3e334f
4
+ data.tar.gz: b9ddf9a82a9989b270867472363897801d88c108
5
5
  SHA512:
6
- metadata.gz: d87e041f9caacf82a0ec9c69bb7860b08925deedbfec266352b64436038c0a11645deca8652ed1b31f1963c6d10f4c449041bcdeb8f8d2b8df2e6467f25d19ed
7
- data.tar.gz: 4da0a6a9178291ab0bd1aa947f280bea8841cd578a5b9e990afeb2c3833165bd6150fe4b8d4679f8b3f59993fa11e4215b933d3d94313e0288169fb15829b00b
6
+ metadata.gz: 9b2b10510a8ae40a4cc4d4518d577dd26f5642903460cbdbc5f1ab87fa4a66347adb8492dc28cec50ac3d4ca6a8424437d98bbeadf9ef207d11270289c6ca57b
7
+ data.tar.gz: ea939be13d5d4582ed33052b4abd70e249ee48f46dd559308c2ab705cef14671935c64fc477a160b6a2450b9de6d0fc0bdf2f013ce97a731f7472eded2b68366
data/.travis.yml CHANGED
@@ -1,5 +1,7 @@
1
1
  language: ruby
2
2
  cache: bundler
3
+ script:
4
+ - bundle exec rake spec environment=test
3
5
  sudo: false
4
6
  rvm:
5
7
  - 2.2
@@ -17,4 +19,4 @@ notifications:
17
19
  channels:
18
20
  - "irc.freenode.org#projecthydra"
19
21
  template:
20
- - "%{repository}//%{branch}@%{commit} by %{author}: %{message} - %{build_url}"
22
+ - "%{repository}//%{branch}@%{commit} by %{author}: %{message} - %{build_url}"
data/Rakefile CHANGED
@@ -3,3 +3,5 @@ require 'rspec/core/rake_task'
3
3
 
4
4
  task default: :spec
5
5
  RSpec::Core::RakeTask.new
6
+
7
+ import './lib/tasks/noid_tasks.rake'
@@ -23,4 +23,12 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.7"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency 'rspec', '~> 3.2'
26
+
27
+ spec.post_install_message = <<-END
28
+ NOTE: ActiveFedora::Noid 1.0.0 included a change that breaks existing minter
29
+ statefiles. Run the `active_fedora:noid:migrate_statefile` rake task to migrate
30
+ your statefile. (If you're using a custom statefile, not /tmp/minter-state,, set
31
+ an environment variable called AFNOID_STATEFILE with its path.)
32
+ END
33
+
26
34
  end
@@ -12,14 +12,25 @@ module ActiveFedora
12
12
  end
13
13
 
14
14
  def translate_uri_to_id
15
- lambda { |uri| URI(uri).path.split('/', 9).last }
15
+ lambda { |uri| URI(uri).path.split('/', baseparts).last }
16
16
  end
17
17
 
18
18
  def translate_id_to_uri
19
19
  lambda do |id|
20
- "#{ActiveFedora.fedora.host}#{ActiveFedora.fedora.base_path}/#{ActiveFedora::Noid.treeify(id)}"
20
+ "#{baseurl}/#{ActiveFedora::Noid.treeify(id)}"
21
21
  end
22
22
  end
23
+
24
+ private
25
+
26
+ def baseurl
27
+ "#{ActiveFedora.fedora.host}#{ActiveFedora.fedora.base_path}"
28
+ end
29
+
30
+ def baseparts
31
+ treeparts = [(template.gsub(/\.[rsz]/,'').length.to_f/2).ceil, 4].min
32
+ baseurl.count('/') + treeparts
33
+ end
23
34
  end
24
35
  end
25
36
  end
@@ -1,6 +1,4 @@
1
1
  require 'noid'
2
- require 'yaml'
3
-
4
2
  module ActiveFedora
5
3
  module Noid
6
4
  class SynchronizedMinter
@@ -34,16 +32,22 @@ module ActiveFedora
34
32
  @statefile ||= ActiveFedora::Noid.config.statefile
35
33
  end
36
34
 
35
+ def state_for(io_object)
36
+ Marshal.load(io_object.read)
37
+ rescue TypeError, ArgumentError
38
+ { template: template }
39
+ end
40
+
37
41
  def next_id
38
42
  id = ''
39
43
  ::File.open(statefile, ::File::RDWR|::File::CREAT, 0644) do |f|
40
44
  f.flock(::File::LOCK_EX)
41
- yaml = ::YAML::load(f.read) || { template: template }
42
- minter = ::Noid::Minter.new(yaml)
45
+ state = state_for(f)
46
+ minter = ::Noid::Minter.new(state)
43
47
  id = minter.mint
44
48
  f.rewind
45
- yaml = ::YAML::dump(minter.dump)
46
- f.write yaml
49
+ new_state = Marshal.dump(minter.dump)
50
+ f.write(new_state)
47
51
  f.flush
48
52
  f.truncate(f.pos)
49
53
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveFedora
2
2
  module Noid
3
- VERSION = '0.3.0'
3
+ VERSION = '1.0.1'
4
4
  end
5
5
  end
@@ -0,0 +1,29 @@
1
+ require 'active_fedora/noid'
2
+ require 'noid'
3
+ require 'yaml'
4
+
5
+ namespace :active_fedora do
6
+ namespace :noid do
7
+ desc 'Migrate minter state file from YAML to Marshal'
8
+ task :migrate_statefile do
9
+ statefile = ENV.fetch('AFNOID_STATEFILE', ActiveFedora::Noid.config.statefile)
10
+ raise "File not found: #{statefile}\nAborting" unless File.exist?(statefile)
11
+ puts "Migrating #{statefile} from YAML to Marshal serialization..."
12
+ File.open(statefile, File::RDWR | File::CREAT, 0644) do |f|
13
+ f.flock(File::LOCK_EX)
14
+ begin
15
+ yaml_state = YAML.load(f)
16
+ rescue Psych::SyntaxError
17
+ raise "File not valid YAML: #{statefile}\nAborting."
18
+ end
19
+ minter = Noid::Minter.new(yaml_state)
20
+ f.rewind
21
+ new_state = Marshal.dump(minter.dump)
22
+ f.write(new_state)
23
+ f.flush
24
+ f.truncate(f.pos)
25
+ end
26
+ puts "Done!"
27
+ end
28
+ end
29
+ end
@@ -25,10 +25,44 @@ describe ActiveFedora::Noid::Config do
25
25
  end
26
26
 
27
27
  describe '#translate_uri_to_id' do
28
- let(:translator) { described_class.new.translate_uri_to_id }
28
+ let(:config) { described_class.new }
29
+ let(:translator) { config.translate_uri_to_id }
29
30
  let(:uri) { "http://localhost:8983/fedora/rest/test/hh/63/vz/22/hh63vz22q/members" }
31
+ let(:ActiveFedora) { double(ActiveFedora) }
30
32
  subject { translator.call(uri) }
33
+ before do
34
+ allow(ActiveFedora).to receive_message_chain("fedora.host") { "http://localhost:8983" }
35
+ allow(ActiveFedora).to receive_message_chain("fedora.base_path") { "/fedora/rest/test" }
36
+ end
31
37
 
32
38
  it { is_expected.to eq 'hh63vz22q/members' }
39
+
40
+ describe 'with a short custom template' do
41
+ let(:uri) { "http://localhost:8983/fedora/rest/test/ab/cd/abcd/members" }
42
+ let(:custom_template) { '.reeee' }
43
+ before { config.template = custom_template }
44
+ subject { translator.call(uri) }
45
+
46
+ it { is_expected.to eq 'abcd/members' }
47
+ end
48
+
49
+ describe 'with an even shorter custom template' do
50
+ let(:uri) { "http://localhost:8983/fedora/rest/test/ab/c/abc/members" }
51
+ let(:custom_template) { '.reee' }
52
+ before { config.template = custom_template }
53
+ subject { translator.call(uri) }
54
+
55
+ it { is_expected.to eq 'abc/members' }
56
+ end
57
+
58
+ describe 'with a long custom template' do
59
+ let(:uri) { "http://localhost:8983/fedora/rest/test/ab/cd/ef/gh/abcdefghijklmnopqrstuvwxyz/members" }
60
+ let(:custom_template) { '.reeeeeeeeeeeeeeeeeeeeeeeeee' }
61
+ before { config.template = custom_template }
62
+ subject { translator.call(uri) }
63
+
64
+ it { is_expected.to eq 'abcdefghijklmnopqrstuvwxyz/members' }
65
+ end
66
+
33
67
  end
34
68
  end
@@ -4,8 +4,8 @@ require 'active_fedora'
4
4
  describe ActiveFedora::Noid::SynchronizedMinter do
5
5
  it { is_expected.to respond_to(:mint) }
6
6
 
7
- it 'has a default template' do
8
- expect(subject.template).to eq ActiveFedora::Noid.config.template
7
+ it 'has a default statefile' do
8
+ expect(subject.statefile).to eq ActiveFedora::Noid.config.statefile
9
9
  end
10
10
 
11
11
  it 'has a default template' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_fedora-noid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael J. Giarlo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-14 00:00:00.000000000 Z
11
+ date: 2015-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active-fedora
@@ -100,6 +100,7 @@ files:
100
100
  - lib/active_fedora/noid/service.rb
101
101
  - lib/active_fedora/noid/synchronized_minter.rb
102
102
  - lib/active_fedora/noid/version.rb
103
+ - lib/tasks/noid_tasks.rake
103
104
  - spec/spec_helper.rb
104
105
  - spec/unit/config_spec.rb
105
106
  - spec/unit/noid_spec.rb
@@ -109,7 +110,11 @@ homepage: https://github.com/projecthydra-labs/active_fedora-noid
109
110
  licenses:
110
111
  - Apache2
111
112
  metadata: {}
112
- post_install_message:
113
+ post_install_message: |
114
+ NOTE: ActiveFedora::Noid 1.0.0 included a change that breaks existing minter
115
+ statefiles. Run the `active_fedora:noid:migrate_statefile` rake task to migrate
116
+ your statefile. (If you're using a custom statefile, not /tmp/minter-state,, set
117
+ an environment variable called AFNOID_STATEFILE with its path.)
113
118
  rdoc_options: []
114
119
  require_paths:
115
120
  - lib
@@ -125,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
130
  version: '0'
126
131
  requirements: []
127
132
  rubyforge_project:
128
- rubygems_version: 2.4.8
133
+ rubygems_version: 2.4.5
129
134
  signing_key:
130
135
  specification_version: 4
131
136
  summary: Noid identifier services for ActiveFedora-based applications