ldp 0.7.1 → 1.0.3

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.
@@ -2,7 +2,7 @@ module Ldp
2
2
  class PreferHeaders
3
3
  attr_reader :headers_string
4
4
 
5
- def initialize(headers_string="")
5
+ def initialize(headers_string = "")
6
6
  @headers_string = headers_string
7
7
  end
8
8
 
@@ -54,11 +54,11 @@ module Ldp
54
54
  end
55
55
 
56
56
  def options
57
- headers_string.gsub('"',"").
58
- split(";").
59
- map{|x| x.strip.split("=")}.
60
- map{|x| { x[0] => x[1].split(" ") }}.
61
- inject({}, &:merge)
57
+ headers_string.gsub('"', "")
58
+ .split(";")
59
+ .map { |x| x.strip.split("=") }
60
+ .map { |x| { x[0] => x[1].split(" ") } }
61
+ .inject({}, &:merge)
62
62
  end
63
63
  end
64
64
  end
data/lib/ldp/error.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Ldp
2
2
  class Error < StandardError; end
3
-
3
+
4
4
  class HttpError < RuntimeError; end
5
5
  class BadRequest < HttpError; end # 400
6
6
  class NotFound < HttpError; end # 404
data/lib/ldp/orm.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module Ldp
2
2
  class Orm
3
-
4
3
  attr_reader :resource
5
4
  attr_reader :last_response
6
5
 
data/lib/ldp/resource.rb CHANGED
@@ -57,8 +57,8 @@ module Ldp
57
57
  def head
58
58
  @head ||= begin
59
59
  @get || client.head(subject)
60
- rescue Ldp::NotFound
61
- None
60
+ rescue Ldp::NotFound
61
+ None
62
62
  end
63
63
  end
64
64
 
@@ -79,7 +79,7 @@ module Ldp
79
79
  # @return [RdfSource] the new representation
80
80
  # @raise [Ldp::Conflict] if you attempt to call create on an existing resource
81
81
  def create &block
82
- raise Ldp::Conflict, "Can't call create on an existing resource" unless new?
82
+ raise Ldp::Conflict, "Can't call create on an existing resource (#{subject})" unless new?
83
83
  verb = subject.nil? ? :post : :put
84
84
  resp = client.send(verb, (subject || @base_path), content) do |req|
85
85
  req.headers["Link"] = "<#{interaction_model}>;rel=\"type\"" if interaction_model
@@ -130,6 +130,5 @@ module Ldp
130
130
  def interaction_model
131
131
  nil
132
132
  end
133
-
134
133
  end
135
134
  end
@@ -2,16 +2,21 @@ module Ldp
2
2
  class Resource::BinarySource < Ldp::Resource
3
3
  attr_accessor :content
4
4
 
5
+ # @param client [Ldp::Client]
6
+ # @param subject [String] the URI for the resource
7
+ # @param content_or_response [String,Ldp::Response]
8
+ # @param base_path [String] ('')
5
9
  def initialize client, subject, content_or_response = nil, base_path = ''
6
10
  super
7
11
 
8
12
  case content_or_response
9
- when Faraday::Response
13
+ when Ldp::Response
10
14
  else
11
15
  @content = content_or_response
12
16
  end
13
17
  end
14
18
 
19
+ # @return [Ldp::Response]
15
20
  def content
16
21
  @content ||= get.body
17
22
  end
@@ -25,7 +30,7 @@ module Ldp
25
30
  # Override inspect so that `content` is never shown. It is typically too big to be helpful
26
31
  def inspect
27
32
  string = "#<#{self.class.name}:#{self.object_id} "
28
- fields = [:subject].map{|field| "#{field}=\"#{self.send(field)}\""}
33
+ fields = [:subject].map { |field| "#{field}=\"#{self.send(field)}\"" }
29
34
  string << fields.join(", ") << ">"
30
35
  end
31
36
 
@@ -1,18 +1,17 @@
1
1
  require 'rdf/turtle'
2
2
  module Ldp
3
3
  class Resource::RdfSource < Ldp::Resource
4
-
5
4
  def initialize client, subject, graph_or_response = nil, base_path = ''
6
5
  super
7
6
 
8
7
  case graph_or_response
9
- when RDF::Enumerable
10
- @graph = graph_or_response
11
- when Ldp::Response
12
- when NilClass
13
- #nop
14
- else
15
- raise ArgumentError, "Third argument to #{self.class}.new should be a RDF::Enumerable or a Ldp::Response. You provided #{graph_or_response.class}"
8
+ when RDF::Enumerable
9
+ @graph = graph_or_response
10
+ when Ldp::Response
11
+ when NilClass
12
+ # nop
13
+ else
14
+ raise ArgumentError, "Third argument to #{self.class}.new should be a RDF::Enumerable or a Ldp::Response. You provided #{graph_or_response.class}"
16
15
  end
17
16
  end
18
17
 
@@ -66,41 +65,32 @@ module Ldp
66
65
  end
67
66
 
68
67
  private
69
- ##
70
- # @param [Faraday::Response] graph query response
71
- # @return [RDF::Graph]
72
- def response_as_graph(resp)
73
- graph = build_empty_graph
74
- resp.each_statement do |stmt|
75
- graph << stmt
76
- end
77
- graph
78
- end
79
-
80
- ##
81
- # @param [RDF::Graph] original_graph The graph returned by the LDP server
82
- # @return [RDF::Graph] A graph stripped of any inlined resources present in the original
83
- def filtered_graph(original_graph)
84
- inlined_resources = original_graph.query(predicate: RDF::Vocab::LDP.contains).map { |x| x.object }
85
68
 
86
- # we want to scope this graph to just statements about this model, not contained relations
87
- if inlined_resources.empty?
88
- original_graph
89
- else
90
- graph_without_inlined_resources(original_graph, inlined_resources)
91
- end
92
- end
93
-
94
- def graph_without_inlined_resources(original_graph, inlined_resources)
95
- new_graph = build_empty_graph
69
+ ##
70
+ # @note tries to avoid doing a large scale copy of the {RDF::Repository}
71
+ # data structure by using the existing {Ldp::Response#graph} if
72
+ # {#graph_class} is {RDF::Graph}. otherwise, it tries to instantiate a
73
+ # new graph projected over the same underlying {RDF::Graph#data}. finally,
74
+ # if {#graph_class}'s initailizer doesn't accept a `data:` parameter, it
75
+ # shovels {Ldp::Response#graph} into a new object of that class.
76
+ #
77
+ # @param [Faraday::Response] graph query response
78
+ # @return [RDF::Graph]
79
+ def response_as_graph(resp)
80
+ build_empty_graph << resp.graph
81
+ end
96
82
 
97
- original_graph.each_statement do |s|
98
- unless inlined_resources.include? s.subject
99
- new_graph << s
100
- end
101
- end
83
+ ##
84
+ # @param [RDF::Graph] original_graph The graph returned by the LDP server
85
+ # @return [RDF::Graph] A graph stripped of any inlined resources present in the original
86
+ def filtered_graph(original_graph)
87
+ contains_statements = original_graph.query(predicate: RDF::Vocab::LDP.contains)
102
88
 
103
- new_graph
89
+ contains_statements.each_object do |contained_uri|
90
+ original_graph.delete(original_graph.query(subject: contained_uri))
104
91
  end
92
+
93
+ original_graph
94
+ end
105
95
  end
106
96
  end
data/lib/ldp/response.rb CHANGED
@@ -10,6 +10,7 @@ module Ldp
10
10
 
11
11
  attr_writer :etag, :last_modified
12
12
 
13
+ # @param response [Faraday::Response]
13
14
  def initialize(response)
14
15
  @response = response
15
16
  end
@@ -78,10 +79,10 @@ module Ldp
78
79
  # Get the subject for the response
79
80
  def subject
80
81
  @subject ||= if has_page?
81
- graph.first_object [page_subject, RDF::Vocab::LDP.pageOf, nil]
82
- else
83
- page_subject
84
- end
82
+ graph.first_object [page_subject, RDF::Vocab::LDP.pageOf, nil]
83
+ else
84
+ page_subject
85
+ end
85
86
  end
86
87
 
87
88
  ##
@@ -104,9 +105,7 @@ module Ldp
104
105
  # Get the graph for the resource (or a blank graph if there is no metadata for the resource)
105
106
  def graph
106
107
  @graph ||= begin
107
- graph = RDF::Graph.new
108
- each_statement { |s| graph << s }
109
- graph
108
+ RDF::Graph.new << reader
110
109
  end
111
110
  end
112
111
 
@@ -114,6 +113,8 @@ module Ldp
114
113
  reader_for_content_type.new(body, base_uri: page_subject, &block)
115
114
  end
116
115
 
116
+ ##
117
+ # @deprecated use {#graph} instead
117
118
  def each_statement(&block)
118
119
  reader do |reader|
119
120
  reader.each_statement(&block)
@@ -154,17 +155,9 @@ module Ldp
154
155
  # Statements about the page
155
156
  def page
156
157
  @page_graph ||= begin
157
- g = RDF::Graph.new
158
-
159
- if resource?
160
- res = graph.query RDF::Statement.new(page_subject, nil, nil)
161
-
162
- res.each_statement do |s|
163
- g << s
164
- end
165
- end
166
-
167
- g
158
+ page_graph = RDF::Graph.new
159
+ page_graph << graph.query([page_subject, nil, nil]) if resource?
160
+ page_graph
168
161
  end
169
162
  end
170
163
 
@@ -208,7 +201,7 @@ module Ldp
208
201
  def content_disposition_attributes
209
202
  parts = headers['Content-Disposition'].split(/;\s*/).collect { |entry| entry.split(/\s*=\s*/) }
210
203
  entries = parts.collect do |part|
211
- value = part[1].respond_to?(:sub) ? part[1].sub(%r{^"(.+)"$}, '\1') : part[1]
204
+ value = part[1].respond_to?(:sub) ? part[1].sub(%r{^"(.*)"$}, '\1') : part[1]
212
205
  [part[0], value]
213
206
  end
214
207
  Hash[entries]
data/lib/ldp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ldp
2
- VERSION = "0.7.1"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -4,21 +4,26 @@ describe Ldp::Resource::BinarySource do
4
4
  let(:client) { instance_double(Ldp::Client) }
5
5
  let(:uri) { 'http://example.com/foo/bar' }
6
6
  let(:content) { 'somecontent' }
7
- subject { described_class.new(client, uri, content) }
7
+ let(:instance) { described_class.new(client, uri, content) }
8
8
 
9
- it "should not display content to inspect" do
10
- expect(subject.inspect).to match /subject=\"http:\/\/example\.com\/foo\/bar\"/
11
- expect(subject.inspect).not_to match /somecontent/
9
+ describe "#inspect" do
10
+ subject { instance.inspect }
11
+
12
+ it "does not display content" do
13
+ expect(subject).to match /subject=\"http:\/\/example\.com\/foo\/bar\"/
14
+ expect(subject).not_to match /somecontent/
15
+ end
12
16
  end
13
17
 
14
18
  describe '#described_by' do
19
+ subject { instance.described_by }
15
20
  context 'without a description' do
16
21
  before do
17
22
  allow(client).to receive(:head).and_return(instance_double(Ldp::Response, links: { }))
18
23
  end
19
24
 
20
25
  it 'retrieves the description object' do
21
- expect(subject.described_by).to eq nil
26
+ expect(subject).to eq nil
22
27
  end
23
28
  end
24
29
 
@@ -31,8 +36,20 @@ describe Ldp::Resource::BinarySource do
31
36
  let(:desc) { double }
32
37
 
33
38
  it 'retrieves the description object' do
34
- expect(subject.described_by).to eq desc
39
+ expect(subject).to eq desc
35
40
  end
36
41
  end
37
42
  end
43
+
44
+ describe "#content" do
45
+ context "when an Ldp::Response is passed in" do
46
+ let(:mock_response) { instance_double(Faraday::Response, headers: {}, env: { url: "info:a" }) }
47
+ let(:content) { Ldp::Response.new(mock_response) }
48
+ let(:client) { instance_double(Ldp::Client, get: double(body: 'retrieved value')) }
49
+
50
+ subject { instance.content }
51
+
52
+ it { is_expected.to eq 'retrieved value' }
53
+ end
54
+ end
38
55
  end
@@ -107,6 +107,24 @@ describe Ldp::Resource::RdfSource do
107
107
  expect(subject.graph.size).to eql(1)
108
108
  end
109
109
  end
110
+
111
+ context 'with inlined resources' do
112
+ subject { Ldp::Resource::RdfSource.new mock_client, "http://my.ldp.server/existing_object" }
113
+
114
+ let(:simple_graph) do
115
+ graph = RDF::Graph.new
116
+ graph << [RDF::URI.new(), RDF::Vocab::DC.title, "Hello, world!"]
117
+ graph << [RDF::URI.new(), RDF::Vocab::LDP.contains, contained_uri]
118
+ graph << [contained_uri, RDF::Vocab::DC.title, "delete me"]
119
+ end
120
+
121
+ let(:contained_uri) { RDF::URI.new('http://example.com/contained') }
122
+
123
+ it do
124
+ expect(subject.graph.subjects)
125
+ .to contain_exactly(RDF::URI('http://my.ldp.server/existing_object'))
126
+ end
127
+ end
110
128
  end
111
129
 
112
130
  context "When graph_class is overridden" do
@@ -130,5 +148,14 @@ describe Ldp::Resource::RdfSource do
130
148
  it "should use the specified class" do
131
149
  expect(subject.graph).to be_a SpecialGraph
132
150
  end
151
+
152
+ context "with a response body" do
153
+ subject { SpecialResource.new mock_client, "http://my.ldp.server/existing_object" }
154
+
155
+
156
+ it "should use the specified class" do
157
+ expect(subject.graph).to be_a SpecialGraph
158
+ end
159
+ end
133
160
  end
134
161
  end
@@ -202,11 +202,13 @@ describe Ldp::Response do
202
202
  { 'Content-Disposition' => 'filename="xyz.txt";' },
203
203
  { 'Content-Disposition' => 'attachment; filename=xyz.txt' },
204
204
  { 'Content-Disposition' => 'attachment; filename="xyz.txt"; size="12345"' },
205
+ { 'Content-Disposition' => 'attachment; filename=""; size="12345"' },
205
206
  )
206
207
  end
207
208
 
208
209
  it 'provides the filename from the content disposition header' do
209
210
  3.times { expect(subject.content_disposition_filename).to eq 'xyz.txt' }
211
+ expect(subject.content_disposition_filename).to eq ''
210
212
  end
211
213
  end
212
214
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ldp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-13 00:00:00.000000000 Z
11
+ date: 2021-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '1.3'
145
+ version: '2.0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '1.3'
152
+ version: '2.0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: rake
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -206,6 +206,48 @@ dependencies:
206
206
  - - ">="
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: rspec_junit_formatter
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: bixby
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: 3.0.0
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: 3.0.0
237
+ - !ruby/object:Gem::Dependency
238
+ name: github_changelog_generator
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
209
251
  description: Linked Data Platform client library
210
252
  email:
211
253
  - chris@cbeer.info
@@ -214,13 +256,19 @@ executables:
214
256
  extensions: []
215
257
  extra_rdoc_files: []
216
258
  files:
259
+ - ".circleci/config.yml"
260
+ - ".github_changelog_generator"
217
261
  - ".gitignore"
218
- - ".travis.yml"
262
+ - ".rubocop.yml"
263
+ - ".rubocop_todo.yml"
264
+ - CHANGELOG.md
265
+ - CODE_OF_CONDUCT.md
219
266
  - CONTRIBUTING.md
220
267
  - Gemfile
221
268
  - LICENSE.txt
222
269
  - README.md
223
270
  - Rakefile
271
+ - SUPPORT.md
224
272
  - bin/ldp
225
273
  - ldp.gemspec
226
274
  - lib/ldp.rb
@@ -252,7 +300,7 @@ homepage: https://github.com/projecthydra/ldp
252
300
  licenses:
253
301
  - APACHE2
254
302
  metadata: {}
255
- post_install_message:
303
+ post_install_message:
256
304
  rdoc_options: []
257
305
  require_paths:
258
306
  - lib
@@ -267,9 +315,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
315
  - !ruby/object:Gem::Version
268
316
  version: '0'
269
317
  requirements: []
270
- rubyforge_project:
271
- rubygems_version: 2.7.3
272
- signing_key:
318
+ rubygems_version: 3.1.4
319
+ signing_key:
273
320
  specification_version: 4
274
321
  summary: Linked Data Platform client library
275
322
  test_files: