fedora_lens 0.0.7 → 0.0.8

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: 1851950ca061fabd4b2a32c699778accbcbfbce2
4
- data.tar.gz: d45a09d0ee487eb21fd118acc97a97b9df4d0299
3
+ metadata.gz: cc2ee8880920469db171ffad4c5039137a46e796
4
+ data.tar.gz: 0d3790c53ea006a2180a78916173dfe84e9ea96a
5
5
  SHA512:
6
- metadata.gz: ee264c445d33e8a9637e24c826081525719cc37208159d57d26c70c43994783167fa962eae0485681732eedb583976409ab4bf7c00c0856b68df85454cda4bb3
7
- data.tar.gz: 14c1c41dbba783f45030c2e0f22f9d12af28596acfd31768deb8dff02953dd69d9dd913de0214b0d05da5d5f0dc3d84185baeb4d73cca63418721ea5d3a3591d
6
+ metadata.gz: a33e640c5822d859f7bf466c9a62b9d42433f699ab8965e29f7da2e673ff9aa805f2bc035b068126aa43a0bb32ba0cffcb211c6eac66d492b771477e932010eb
7
+ data.tar.gz: 4b89d671befc602a69c7769e308c0503026bd55413db50f27c55a4a5d3c4f94b7ad340996a11e58975a802f3eed4afa254a33c0140c9899cddd78e061c8b7035
data/Gemfile CHANGED
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
+ gem 'ldp', github: 'cbeer/ldp'
5
6
  gem 'jettywrapper'
6
7
 
7
8
  group :development, :test do
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-4a4.zip"
8
+ ZIP_URL = "https://github.com/projecthydra/hydra-jetty/archive/fedora-4a5.zip"
9
9
  require 'jettywrapper'
10
10
 
11
11
  task default: :ci
data/fedora_lens.gemspec CHANGED
@@ -26,5 +26,5 @@ Gem::Specification.new do |spec|
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.3'
29
+ spec.add_dependency 'ldp', '0.0.4'
30
30
  end
data/lib/fedora_lens.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rdf'
2
2
  require 'ldp'
3
- require 'ldp_monkeypatch'
4
3
  require 'rdf/turtle'
5
4
  require 'nokogiri'
6
5
  require 'active_model'
@@ -26,9 +25,8 @@ module FedoraLens
26
25
  end
27
26
  end
28
27
 
29
- HOST = "http://localhost:8983/fedora"
28
+ HOST = "http://localhost:8983/fedora/rest"
30
29
  #HOST = "http://localhost:8080"
31
- PATH = '/rest'
32
30
 
33
31
  def self.connection
34
32
  @@connection ||= Ldp::Client.new(HOST)
@@ -78,7 +76,7 @@ module FedoraLens
78
76
  end
79
77
 
80
78
  def new_record?
81
- @new_record
79
+ @orm.resource.new?
82
80
  end
83
81
 
84
82
  def uri
@@ -92,40 +90,32 @@ module FedoraLens
92
90
  protected
93
91
  # This allows you to overide the initializer, but still use this behavior
94
92
  def init_core(subject_or_data = {}, data = nil)
95
- @new_record = true
96
93
  case subject_or_data
97
- when Ldp::Resource
94
+ when Ldp::Resource::RdfSource
98
95
  @orm = Ldp::Orm.new(subject_or_data)
99
96
  @attributes = get_attributes_from_orm(@orm)
100
97
  when NilClass, Hash
101
98
  data = subject_or_data || {}
102
- @orm = Ldp::Orm.new(Ldp::Resource.new(FedoraLens.connection, nil, RDF::Graph.new))
99
+ @orm = Ldp::Orm.new(Ldp::Resource::RdfSource.new(FedoraLens.connection, nil, RDF::Graph.new))
103
100
  @attributes = data.with_indifferent_access
104
101
  when String
105
102
  data ||= {}
106
- @orm = Ldp::Orm.new(Ldp::Resource.new(FedoraLens.connection, subject_or_data, RDF::Graph.new))
103
+ @orm = Ldp::Orm.new(Ldp::Resource::RdfSource.new(FedoraLens.connection, subject_or_data, RDF::Graph.new))
107
104
  @attributes = data.with_indifferent_access
108
105
  else
109
- raise ArgumentError, "#{data.class} is not acceptable"
106
+ raise ArgumentError, "#{subject_or_data.class} is not acceptable"
110
107
  end
111
108
  end
112
109
 
113
110
  def create_record
114
111
  push_attributes_to_orm
115
- orm.resource.create
116
- @new_record = false
112
+ @orm = orm.create
117
113
  true
118
114
  end
119
115
 
120
116
  def update_record
121
117
  push_attributes_to_orm
122
- # Fedora errors out when you try to set the rdf:type
123
- # see https://github.com/cbeer/ldp/issues/2
124
- orm.graph.delete([@orm.resource.subject_uri,
125
- RDF::URI.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
126
- nil])
127
- orm.save
128
- orm.last_response.success?
118
+ orm.save!
129
119
  end
130
120
 
131
121
 
@@ -141,16 +131,17 @@ module FedoraLens
141
131
 
142
132
  module ClassMethods
143
133
  def find(id)
144
- resource = Ldp::Resource.new(FedoraLens.connection, id_to_uri(id))
134
+ resource = Ldp::Resource::RdfSource.new(FedoraLens.connection, id_to_uri(id))
135
+ raise Ldp::NotFound if resource.new?
145
136
  self.new(resource)
146
137
  end
147
138
 
148
139
  def id_to_uri(id)
149
- "#{HOST}#{PATH}" + (id.start_with?('/') ? id : '/' + id)
140
+ HOST + (id.start_with?('/') ? id : '/' + id)
150
141
  end
151
142
 
152
143
  def uri_to_id(uri)
153
- uri.to_s.sub(HOST + PATH, '')
144
+ uri.to_s.sub(HOST, '')
154
145
  end
155
146
 
156
147
  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 + PATH, '') }
53
+ source.map { |uri| URI.parse(uri).to_s.sub(HOST, '') }
54
54
  end,
55
55
  put: lambda do |sources, values|
56
56
  Array(values).compact.map do |value|
57
- RDF::URI.new(HOST + PATH + value)
57
+ RDF::URI.new(HOST + value)
58
58
  end
59
59
  end
60
60
  ]
@@ -139,7 +139,7 @@ module FedoraLens
139
139
  orm
140
140
  end,
141
141
  create: lambda do |values|
142
- orm = Ldp::Orm.new(Ldp::Resource.new(nil, '', RDF::Graph.new))
142
+ orm = Ldp::Orm.new(Ldp::Resource::RdfSource.new(FedoraLens.connection, '', RDF::Graph.new))
143
143
  values.each do |value|
144
144
  orm.graph.insert([orm.resource.subject_uri, predicate, value])
145
145
  end
@@ -164,9 +164,9 @@ module FedoraLens
164
164
  Lens[
165
165
  get: lambda do |uri|
166
166
  if uri.present?
167
- Ldp::Orm.new(Ldp::Resource.new(FedoraLens.connection, uri.to_s))
167
+ Ldp::Orm.new(Ldp::Resource::RdfSource.new(FedoraLens.connection, uri.to_s))
168
168
  else
169
- Ldp::Orm.new(Ldp::Resource.new(FedoraLens.connection, nil, RDF::Graph.new))
169
+ Ldp::Orm.new(Ldp::Resource::RdfSource.new(FedoraLens.connection, nil, RDF::Graph.new))
170
170
  end
171
171
  end,
172
172
  put: lambda do |uri, orm|
@@ -1,3 +1,3 @@
1
1
  module FedoraLens
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
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+PATH+'/id/123'), RDF::URI.new(HOST+PATH+'/id/321')] }
62
+ let(:original) { [RDF::URI.new(HOST + '/id/123'), RDF::URI.new(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+PATH+'/id/777'), RDF::URI.new(HOST+PATH+'/id/888')]
88
+ expect(subject).to eq [RDF::URI.new(HOST + '/id/777'), RDF::URI.new(HOST + '/id/888')]
89
89
  end
90
90
  end
91
91
 
@@ -136,33 +136,48 @@ module FedoraLens
136
136
 
137
137
  describe ".get_predicate" do
138
138
  let(:orm) do
139
- graph = RDF::Graph.new
140
- orm = Ldp::Orm.new(Ldp::Resource.new(nil, '', graph))
141
- orm.graph.insert([orm.resource.subject_uri, RDF::DC11.title, "title"])
142
- orm
139
+ Ldp::Orm.new(resource).tap do |orm|
140
+ orm.graph.insert([orm.resource.subject_uri, RDF::DC11.title, "new title"])
141
+ end
143
142
  end
143
+
144
+ let(:resource) { Ldp::Resource::RdfSource.new(mock_conn, '', RDF::Graph.new) }
145
+ let(:mock_conn) { double }
146
+ before { resource.stub(new?: true) }
147
+ subject { Lenses.get_predicate(RDF::DC11.title) }
148
+
149
+ let(:value) { [RDF::Literal.new("new title")] }
150
+
144
151
  it "converts an Ldp::Orm to the value of the specified predicate" do
145
- Lenses.get_predicate(RDF::DC11.title).get(orm).first.should eq RDF::Literal.new("title")
152
+ subject.get(orm).first.should eq value.first
146
153
  end
154
+
147
155
  it "gets an empty set" do
148
156
  Lenses.get_predicate(RDF::DC11.description).get(orm).should eq []
149
157
  end
158
+
159
+ it "is well-behaved (PutGet: get(put(source, value)) == value)" do
160
+ converted = subject.get(subject.put(orm, value))
161
+ expect(converted).to eq value
162
+ end
163
+
150
164
  it "sets the value of an Ldp::Orm for the specified predicate" do
151
- Lenses.get_predicate(RDF::DC11.title).put(orm, [RDF::Literal.new("new")]).value(RDF::DC11.title).first.should eq RDF::Literal.new("new")
165
+ subject.put(orm, [RDF::Literal.new("new")]).value(RDF::DC11.title).first.should eq RDF::Literal.new("new")
166
+ end
167
+
168
+ it "is well-behaved (GetPut: put(source, get(source)) == source)" do
169
+ converted = subject.put(orm, subject.get(orm))
170
+ expect(converted).to eq orm
152
171
  end
172
+
153
173
  it "creates a new Ldp::Orm with the value for a specified predicate" do
154
- converted = Lenses.get_predicate(RDF::DC11.title).create([RDF::Literal.new("title")])
155
- converted.graph.dump(:ttl).should eq orm.graph.dump(:ttl)
156
- end
157
- graph = RDF::Graph.new
158
- orm = Ldp::Orm.new(Ldp::Resource.new(nil, '', graph))
159
- orm.graph.insert([orm.resource.subject_uri, RDF::DC11.title, "title"])
160
- test_lens(Lenses.get_predicate(RDF::DC11.title), orm, [RDF::Literal.new("new title")]) do |v|
161
- if v.is_a? Ldp::Orm
162
- v.value(RDF::DC11.title)
163
- else
164
- v
165
- end
174
+ converted = subject.create(value)
175
+ converted.graph.should eq orm.graph
176
+ end
177
+
178
+ it "is well-behaved (CreateGet: get(create(value)) == value)" do
179
+ created = subject.get(subject.create(value))
180
+ expect(created).to eq value
166
181
  end
167
182
  end
168
183
  end
@@ -75,7 +75,7 @@ describe FedoraLens do
75
75
 
76
76
  describe "#id" do
77
77
  it "should not have 'fedora' in the id" do
78
- m = TestClass.new('http://localhost:8983/fedora/rest/41/0d/6b/47/410d6b47-ce9c-4fa0-91e2-d62765667c52')
78
+ m = TestClass.new(FedoraLens::HOST + '/41/0d/6b/47/410d6b47-ce9c-4fa0-91e2-d62765667c52')
79
79
  expect(m.id).to eq '/41/0d/6b/47/410d6b47-ce9c-4fa0-91e2-d62765667c52'
80
80
  end
81
81
  end
@@ -92,13 +92,15 @@ describe FedoraLens do
92
92
  m = TestClass.create(title: "created resource")
93
93
  m.reload
94
94
  m.title = "changed title"
95
- m.save
95
+ m.save!
96
96
  TestClass.find(m.id).title.should eq "changed title"
97
97
  end
98
98
 
99
99
  context "with a supplied id" do
100
100
  subject { TestClass.new(TestClass.id_to_uri('foobar')) }
101
101
 
102
+ after { subject.delete }
103
+
102
104
  it "saves with that id" do
103
105
  expect(subject.new_record?).to be_true
104
106
  expect(subject.save).to be_true
@@ -112,11 +114,11 @@ describe FedoraLens do
112
114
  subject { TestClass.id_to_uri(id) }
113
115
  context "without a leading slash" do
114
116
  let(:id) { 'test' }
115
- it { should eq 'http://localhost:8983/fedora/rest/test' }
117
+ it { should eq FedoraLens::HOST + '/test' }
116
118
  end
117
119
  context "with a leading slash" do
118
120
  let(:id) { '/test' }
119
- it { should eq 'http://localhost:8983/fedora/rest/test' }
121
+ it { should eq FedoraLens::HOST + '/test' }
120
122
  end
121
123
  end
122
124
 
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.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-17 00:00:00.000000000 Z
12
+ date: 2014-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -121,14 +121,14 @@ dependencies:
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 0.0.3
124
+ version: 0.0.4
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.3
131
+ version: 0.0.4
132
132
  description: ''
133
133
  email:
134
134
  - justin@curationexperts.com
@@ -157,7 +157,6 @@ files:
157
157
  - lib/fedora_lens/lens_tests.rb
158
158
  - lib/fedora_lens/lenses.rb
159
159
  - lib/fedora_lens/version.rb
160
- - lib/ldp_monkeypatch.rb
161
160
  - lib/test_class.rb
162
161
  - spec/fedora_lens/lenses_spec.rb
163
162
  - spec/fedora_lens_spec.rb
@@ -1,22 +0,0 @@
1
- require 'ldp'
2
- module Ldp
3
-
4
- class Resource
5
- def create
6
- # create seems to not be working in ldp, but it's not entirely clear how it should work
7
- # for example, :new? calls :get, which will raise an error when an object doesn't exist,
8
- # this means it is impossible to create anything.
9
- # raise "" if new?
10
- # puts "MONKEY patch create #{client.inspect}"
11
- # puts "Graph #{graph.dump(:ttl)}"
12
- resp = client.post '/fedora/rest', graph.dump(:ttl) do |req|
13
- # req.headers['Slug'] = subject
14
- end
15
-
16
- # puts "Heards #{resp.headers.inspect}"
17
- @subject = resp.headers['Location']
18
- # puts "Loc #{@subject.inspect}"
19
- @subject_uri = nil
20
- end
21
- end
22
- end