fedora_lens 0.0.9 → 0.0.10

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: 3222d73b43ce75e77c9fa65792200ecdd44c0f2b
4
- data.tar.gz: 8b39418761c0dbbe02b3b281f526565411b67c1f
3
+ metadata.gz: f8a0a4bf460274072101c5095f365d6c6a409d7b
4
+ data.tar.gz: 6e0cbfde2267b95dd38fec8621871fd6a9625451
5
5
  SHA512:
6
- metadata.gz: f67898563c473ff9e6d3de1d136dc83d0ca9c55da614d9b635895396c2440daea8b9ff1c4d22f2ce22d5f0249f03edd96e2b7043d8281f20c6b72cfacb9cc43d
7
- data.tar.gz: 037b06ad821e55d3248d4d60ecc80b0cdfdf3b28ac984eeb4238adf09dffb2b316de472111e1f4ef611ca712e3ca45d855fedd3e266f39515a15db5a06a4554a
6
+ metadata.gz: ef00a7de221518a88b701bacc8fc0a9b32f63ae2b5dc5063c9bb83e51a82ecd80bcbd4bee65879355147b5f8374e456fd2587118ad1353391d9b5b4a367f0990
7
+ data.tar.gz: d8775ef12c0e7223111a6d6f5c1b08072eed19ca9883f9b2a119c48686fa6b2d358cd5491a93c7d8f5986f8e6c869aa5381a74cda220aba5dc70002166fed0ad
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ Bundler::GemHelper.install_tasks
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- ZIP_URL = "https://github.com/projecthydra/hydra-jetty/archive/fedora-4a5.zip"
8
+ ZIP_URL = "https://github.com/projecthydra/hydra-jetty/archive/fedora-4a6.zip"
9
9
  require 'jettywrapper'
10
10
 
11
11
  task default: :ci
data/fedora_lens.gemspec CHANGED
@@ -20,11 +20,11 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "rspec", '~> 2.99'
24
24
  spec.add_development_dependency "childprocess"
25
25
 
26
26
  spec.add_dependency 'rdf-turtle', '~> 1.1.2'
27
27
  spec.add_dependency 'activemodel', '>= 4.0.2', "< 5.0"
28
28
  spec.add_dependency 'nokogiri', '~> 1.6.1'
29
- spec.add_dependency 'ldp', '0.0.5'
29
+ spec.add_dependency 'ldp', '0.0.6'
30
30
  end
data/lib/fedora_lens.rb CHANGED
@@ -26,10 +26,36 @@ module FedoraLens
26
26
  end
27
27
 
28
28
  HOST = "http://localhost:8983/fedora/rest"
29
- #HOST = "http://localhost:8080"
30
29
 
31
- def self.connection
32
- @@connection ||= Ldp::Client.new(HOST)
30
+ class << self
31
+ def connection
32
+ @@connection ||= Ldp::Client.new(host)
33
+ end
34
+
35
+ def host
36
+ HOST
37
+ end
38
+
39
+ def base_path
40
+ @@base_path ||= ''
41
+ end
42
+
43
+ # Set a base path if you want to put all your objects below a certain path
44
+ # example:
45
+ # FedoraLens.base_path = '/text
46
+ def base_path= path
47
+ @@base_path = path
48
+ end
49
+
50
+ def id_to_uri(id)
51
+ id = "/#{id}" unless id.start_with? '/'
52
+ id = FedoraLens.base_path + id unless id.start_with? "#{FedoraLens.base_path}/"
53
+ FedoraLens.host + id
54
+ end
55
+
56
+ def uri_to_id(uri)
57
+ uri.to_s.sub(FedoraLens.host + FedoraLens.base_path, '')
58
+ end
33
59
  end
34
60
 
35
61
  included do
@@ -96,7 +122,7 @@ module FedoraLens
96
122
  @attributes = get_attributes_from_orm(@orm)
97
123
  when NilClass, Hash
98
124
  data = subject_or_data || {}
99
- @orm = Ldp::Orm.new(Ldp::Resource::RdfSource.new(FedoraLens.connection, nil, RDF::Graph.new))
125
+ @orm = Ldp::Orm.new(Ldp::Resource::RdfSource.new(FedoraLens.connection, nil, RDF::Graph.new, FedoraLens.host + FedoraLens.base_path))
100
126
  @attributes = data.with_indifferent_access
101
127
  when String
102
128
  data ||= {}
@@ -109,18 +135,45 @@ module FedoraLens
109
135
 
110
136
  def create_record
111
137
  push_attributes_to_orm
112
- @orm = orm.create
138
+ create_and_fetch_attributes
113
139
  true
114
140
  end
115
141
 
116
142
  def update_record
117
143
  push_attributes_to_orm
118
- orm.save!
144
+ update_and_fetch_attributes
119
145
  end
120
146
 
121
147
 
122
148
  private
123
149
 
150
+ def update_and_fetch_attributes
151
+ orm.save!.tap do
152
+ clear_cached_response
153
+ # This is slow, but it enables us to get attributes like http://fedora.info/definitions/v4/repository#lastModified
154
+ # TODO perhaps attributes could be lazily fetched
155
+ @attributes = get_attributes_from_orm(@orm)
156
+ clear_cached_response
157
+ end
158
+ end
159
+
160
+ def create_and_fetch_attributes
161
+ @orm = orm.create
162
+ # This is slow, but it enables us to get attributes like http://fedora.info/definitions/v4/repository#created
163
+ # TODO perhaps attributes could be lazily fetched
164
+ @attributes = get_attributes_from_orm(@orm)
165
+ clear_cached_response
166
+ end
167
+
168
+ # TODO this causes slowness because we're losing the cached GET response. However it prevents ETag exceptions caused when a
169
+ # subnode is added before an update.
170
+ def clear_cached_response
171
+ # This strips the current cached response (and ETag) from the current ORM to avoid ETag exceptions on the next update,
172
+ # since the etag will change if a child node is added.
173
+ @orm = Ldp::Orm.new @orm.resource.class.new @orm.resource.client, @orm.resource.subject
174
+ end
175
+
176
+
124
177
  def push_attributes_to_orm
125
178
  @orm = self.class.orm_to_hash.put(@orm, @attributes)
126
179
  end
@@ -137,11 +190,11 @@ module FedoraLens
137
190
  end
138
191
 
139
192
  def id_to_uri(id)
140
- HOST + (id.start_with?('/') ? id : '/' + id)
193
+ FedoraLens.id_to_uri(id)
141
194
  end
142
195
 
143
196
  def uri_to_id(uri)
144
- uri.to_s.sub(HOST, '')
197
+ FedoraLens.uri_to_id(uri)
145
198
  end
146
199
 
147
200
  def create(data)
@@ -50,11 +50,11 @@ module FedoraLens
50
50
  def uris_to_ids
51
51
  Lens[
52
52
  get: lambda do |source|
53
- source.map { |uri| URI.parse(uri).to_s.sub(HOST, '') }
53
+ source.map { |uri| FedoraLens.uri_to_id(URI.parse(uri).to_s) }
54
54
  end,
55
55
  put: lambda do |sources, values|
56
56
  Array(values).compact.map do |value|
57
- RDF::URI.new(HOST + value)
57
+ RDF::URI.new(FedoraLens.id_to_uri(value))
58
58
  end
59
59
  end
60
60
  ]
@@ -1,3 +1,3 @@
1
1
  module FedoraLens
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'
3
3
  end
@@ -59,7 +59,7 @@ module FedoraLens
59
59
  describe ".uris_to_ids" do
60
60
  let(:lens) { Lenses.uris_to_ids }
61
61
 
62
- let(:original) { [RDF::URI.new(HOST + '/id/123'), RDF::URI.new(HOST + '/id/321')] }
62
+ let(:original) { [RDF::URI.new(FedoraLens.host + '/id/123'), RDF::URI.new(FedoraLens.host + '/id/321')] }
63
63
 
64
64
  describe "#get" do
65
65
  subject { lens.get(input) }
@@ -85,7 +85,7 @@ module FedoraLens
85
85
  context "with new values " do
86
86
  let(:input) { ['/id/777', '/id/888'] }
87
87
  it "overwrites the items" do
88
- expect(subject).to eq [RDF::URI.new(HOST + '/id/777'), RDF::URI.new(HOST + '/id/888')]
88
+ expect(subject).to eq [RDF::URI.new(FedoraLens.host + '/id/777'), RDF::URI.new(FedoraLens.host + '/id/888')]
89
89
  end
90
90
  end
91
91
 
@@ -8,20 +8,14 @@ describe FedoraLens do
8
8
  @model = TestClass.new
9
9
  end
10
10
 
11
-
12
- # before do
13
- # require 'logger'
14
- # Ldp.logger = Logger.new(STDOUT).tap do |l|
15
- # l.level = Logger::DEBUG
16
- # end
17
- # end
18
-
19
-
20
11
  context "with a simple class" do
21
12
  before do
22
13
  class TestClass
23
14
  include FedoraLens
24
15
  attribute :title, [RDF::DC11.title, Lenses.single, Lenses.literal_to_string]
16
+ attribute :create_date, [ RDF::URI.new("http://fedora.info/definitions/v4/repository#created"), FedoraLens::Lenses.single, FedoraLens::Lenses.literal_to_string ]
17
+ attribute :modified_date, [ RDF::URI.new("http://fedora.info/definitions/v4/repository#lastModified"), FedoraLens::Lenses.single, FedoraLens::Lenses.literal_to_string ]
18
+
25
19
  end
26
20
  end
27
21
 
@@ -42,7 +36,10 @@ describe FedoraLens do
42
36
  let(:existing) { TestClass.create(title: "created resource") }
43
37
  subject { TestClass.find(existing.id) }
44
38
  it { should be_kind_of TestClass }
45
- its(:id) { should eq existing.id }
39
+
40
+ it "should have the same id" do
41
+ expect(subject.id).to eq existing.id
42
+ end
46
43
  end
47
44
  end
48
45
 
@@ -75,7 +72,7 @@ describe FedoraLens do
75
72
 
76
73
  describe "#id" do
77
74
  it "should not have 'fedora' in the id" do
78
- m = TestClass.new(FedoraLens::HOST + '/41/0d/6b/47/410d6b47-ce9c-4fa0-91e2-d62765667c52')
75
+ m = TestClass.new(FedoraLens.host + '/41/0d/6b/47/410d6b47-ce9c-4fa0-91e2-d62765667c52')
79
76
  expect(m.id).to eq '/41/0d/6b/47/410d6b47-ce9c-4fa0-91e2-d62765667c52'
80
77
  end
81
78
  end
@@ -85,14 +82,15 @@ describe FedoraLens do
85
82
  it "saves a new resource" do
86
83
  m = TestClass.new(title: "created resource")
87
84
  m.save
85
+ expect(m.create_date).to_not be_nil
88
86
  TestClass.find(m.id).title.should eq "created resource"
89
87
  end
90
88
 
91
89
  it "saves an updated resource" do
92
90
  m = TestClass.create(title: "created resource")
93
- m.reload
94
91
  m.title = "changed title"
95
- m.save!
92
+ expect { sleep 1; m.save }.to change { m.modified_date }
93
+ expect(m.modified_date).to_not be_empty
96
94
  TestClass.find(m.id).title.should eq "changed title"
97
95
  end
98
96
 
@@ -102,9 +100,9 @@ describe FedoraLens do
102
100
  after { subject.delete }
103
101
 
104
102
  it "saves with that id" do
105
- expect(subject.new_record?).to be_true
106
- expect(subject.save).to be_true
107
- expect(subject.new_record?).to be_false
103
+ expect(subject.new_record?).to be true
104
+ expect(subject.save).to be true
105
+ expect(subject.new_record?).to be false
108
106
  end
109
107
 
110
108
  end
@@ -112,16 +110,72 @@ describe FedoraLens do
112
110
 
113
111
  describe "id_to_uri" do
114
112
  subject { TestClass.id_to_uri(id) }
115
- context "without a leading slash" do
116
- let(:id) { 'test' }
117
- it { should eq FedoraLens::HOST + '/test' }
113
+ context "no base_path set" do
114
+ context "without a leading slash" do
115
+ let(:id) { 'test' }
116
+ it { should eq FedoraLens.host + '/test' }
117
+ end
118
+ context "with a leading slash" do
119
+ let(:id) { '/test' }
120
+ it { should eq FedoraLens.host + '/test' }
121
+ end
118
122
  end
119
- context "with a leading slash" do
120
- let(:id) { '/test' }
121
- it { should eq FedoraLens::HOST + '/test' }
123
+
124
+ context "with base_path set" do
125
+ before do
126
+ @original_base = FedoraLens.base_path
127
+ FedoraLens.base_path = '/test'
128
+ end
129
+
130
+ after { FedoraLens.base_path = @original_base }
131
+
132
+ context "without a leading slash" do
133
+ let(:id) { 'test-me' }
134
+ it { should eq FedoraLens.host + '/test/test-me' }
135
+ end
136
+ context "with a leading slash" do
137
+ let(:id) { '/test-me' }
138
+ it { should eq FedoraLens.host + '/test/test-me' }
139
+ end
140
+ context "within the base path" do
141
+ let(:id) { '/test/test-me' }
142
+ it { should eq FedoraLens.host + '/test/test-me' }
143
+ end
122
144
  end
123
145
  end
124
146
 
147
+ describe "uri_to_id" do
148
+ subject { TestClass.uri_to_id(uri) }
149
+ context "no base_path set" do
150
+
151
+ context "at the base level" do
152
+ let(:uri) { "#{FedoraLens.host}/test" }
153
+ it { should eq '/test' }
154
+ end
155
+ context "at the second level" do
156
+ let(:uri) { "#{FedoraLens.host}/test/foo" }
157
+ it { should eq '/test/foo' }
158
+ end
159
+ end
160
+
161
+ context "with base_path set" do
162
+ before do
163
+ @original_base = FedoraLens.base_path
164
+ FedoraLens.base_path = '/test'
165
+ end
166
+
167
+ after { FedoraLens.base_path = @original_base }
168
+
169
+ context "at the base level" do
170
+ let(:uri) { "#{FedoraLens.host}/test/foo" }
171
+ it { should eq '/foo' }
172
+ end
173
+ context "at the second level" do
174
+ let(:uri) { "#{FedoraLens.host}/test/foo/bar" }
175
+ it { should eq '/foo/bar' }
176
+ end
177
+ end
178
+ end
125
179
  end
126
180
 
127
181
  context "with a class that has many attributes" do
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,10 @@ require "bundler/setup"
3
3
  require 'fedora_lens'
4
4
  require 'fedora_lens/lenses'
5
5
 
6
+ # HttpLogger.logger = Logger.new(STDOUT)
7
+ # HttpLogger.colorize = false
8
+ # HttpLogger.ignore = [/localhost:8983\/solr/]
9
+
6
10
  RSpec.configure do |config|
7
11
  config.treat_symbols_as_metadata_keys_with_true_values = true
8
12
  config.run_all_when_everything_filtered = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fedora_lens
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
@@ -9,110 +9,110 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-24 00:00:00.000000000 Z
12
+ date: 2014-07-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: '1.5'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ~>
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.5'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '>='
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0'
48
+ version: '2.99'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '>='
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: '2.99'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: childprocess
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - '>='
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - '>='
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rdf-turtle
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ~>
74
+ - - "~>"
75
75
  - !ruby/object:Gem::Version
76
76
  version: 1.1.2
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ~>
81
+ - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: 1.1.2
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: activemodel
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - '>='
88
+ - - ">="
89
89
  - !ruby/object:Gem::Version
90
90
  version: 4.0.2
91
- - - <
91
+ - - "<"
92
92
  - !ruby/object:Gem::Version
93
93
  version: '5.0'
94
94
  type: :runtime
95
95
  prerelease: false
96
96
  version_requirements: !ruby/object:Gem::Requirement
97
97
  requirements:
98
- - - '>='
98
+ - - ">="
99
99
  - !ruby/object:Gem::Version
100
100
  version: 4.0.2
101
- - - <
101
+ - - "<"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '5.0'
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: nokogiri
106
106
  requirement: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 1.6.1
111
111
  type: :runtime
112
112
  prerelease: false
113
113
  version_requirements: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
117
  version: 1.6.1
118
118
  - !ruby/object:Gem::Dependency
@@ -121,14 +121,14 @@ dependencies:
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 0.0.5
124
+ version: 0.0.6
125
125
  type: :runtime
126
126
  prerelease: false
127
127
  version_requirements: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 0.0.5
131
+ version: 0.0.6
132
132
  description: ''
133
133
  email:
134
134
  - justin@curationexperts.com
@@ -136,10 +136,9 @@ executables: []
136
136
  extensions: []
137
137
  extra_rdoc_files: []
138
138
  files:
139
- - .gitignore
140
- - .rspec
141
- - .ruby-version
142
- - .travis.yml
139
+ - ".gitignore"
140
+ - ".rspec"
141
+ - ".travis.yml"
143
142
  - Gemfile
144
143
  - README.md
145
144
  - Rakefile
@@ -171,17 +170,17 @@ require_paths:
171
170
  - lib
172
171
  required_ruby_version: !ruby/object:Gem::Requirement
173
172
  requirements:
174
- - - '>='
173
+ - - ">="
175
174
  - !ruby/object:Gem::Version
176
175
  version: '0'
177
176
  required_rubygems_version: !ruby/object:Gem::Requirement
178
177
  requirements:
179
- - - '>='
178
+ - - ">="
180
179
  - !ruby/object:Gem::Version
181
180
  version: '0'
182
181
  requirements: []
183
182
  rubyforge_project:
184
- rubygems_version: 2.1.11
183
+ rubygems_version: 2.2.2
185
184
  signing_key:
186
185
  specification_version: 4
187
186
  summary: A client for Fedora Commons Repository (fcrepo) version 4
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.0.0-p353