ldp 0.2.1 → 0.2.2

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: a0192dec60a69549a92992ee9a8a17dc7a2e7bea
4
- data.tar.gz: 9f1d63533db1609c91b7ca86d807e645a1148343
3
+ metadata.gz: 652e178917c335b0881ee4e23026d25dc32aa936
4
+ data.tar.gz: 20aa0d107df87615a4159ccc10074f7f8269f006
5
5
  SHA512:
6
- metadata.gz: a2576375233b5f9c8fb7879e26c187c75a0cb30e740db682d084ebd57f88db616d81efaeb6c04d4289fcb10095fe34dca5199f7936ebc1c65028e08f56bae31d
7
- data.tar.gz: 0bcd587f427cefcc0d4d702d57da18389a2b9c602b898a06708d829c28cbfd3a8cb8abff4ed195c7f51d25cd67584a77140d03fbb3f493f6609849bcef1427e6
6
+ metadata.gz: cc468961929d9774a534438c7ce2ed062b603f13dab4251d7fedb3012ccc0290bc188d038e48d142a7cd32505f46249d54b6e75e0b49415554c4fe68b326c5b1
7
+ data.tar.gz: 76423521a6ebf9327fda8ebb4d8526b95e84f038891cda7322c8ec1714c65da84e36f5b8212a6cf38c55cd411c1c0f87e8383881534e58c6da84f4a4fce5d846
@@ -6,6 +6,7 @@ env:
6
6
  - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
7
7
  rvm:
8
8
  - 1.9.3
9
- - 2.0.0
10
- - 2.1.0
9
+ - 2.0
10
+ - 2.1
11
+ - 2.2
11
12
  - jruby-19mode
@@ -2,6 +2,7 @@ module Ldp
2
2
  module Response
3
3
  require 'ldp/response/paging'
4
4
 
5
+ TYPE = 'type'.freeze
5
6
  ##
6
7
  # Wrap the raw Faraday respone with our LDP extensions
7
8
  def self.wrap client, raw_resp
@@ -14,7 +15,7 @@ module Ldp
14
15
  # Extract the Link: headers from the HTTP resource
15
16
  def self.links response
16
17
  h = {}
17
- Array(response.headers["Link"]).map { |x| x.split(", ") }.flatten.inject(h) do |memo, header|
18
+ Array(response.headers['Link'.freeze]).map { |x| x.split(', '.freeze) }.flatten.inject(h) do |memo, header|
18
19
  m = header.match(/<(?<link>.*)>;\s?rel="(?<rel>[^"]+)"/)
19
20
  if m
20
21
  memo[m[:rel]] ||= []
@@ -24,10 +25,10 @@ module Ldp
24
25
  memo
25
26
  end
26
27
  end
27
-
28
+
28
29
  def self.applied_preferences headers
29
30
  h = {}
30
-
31
+
31
32
  Array(headers).map { |x| x.split(",") }.flatten.inject(h) do |memo, header|
32
33
  m = header.match(/(?<key>[^=;]*)(=(?<value>[^;,]*))?(;\s*(?<params>[^,]*))?/)
33
34
  includes = (m[:params].match(/include="(?<include>[^"]+)"/)[:include] || "").split(" ")
@@ -40,7 +41,7 @@ module Ldp
40
41
  # Is the response an LDP resource?
41
42
 
42
43
  def self.resource? response
43
- Array(links(response)["type"]).include? Ldp.resource.to_s
44
+ Array(links(response)[TYPE]).include? Ldp.resource.to_s
44
45
  end
45
46
 
46
47
  ##
@@ -50,23 +51,25 @@ module Ldp
50
51
  Ldp.basic_container,
51
52
  Ldp.direct_container,
52
53
  Ldp.indirect_container
53
- ].any? { |x| Array(links(response)["type"]).include? x.to_s }
54
+ ].any? { |x| Array(links(response)[TYPE]).include? x.to_s }
54
55
  end
55
56
 
56
57
  ##
57
58
  # Is the response an LDP RDFSource?
58
59
  # ldp:Container is a subclass of ldp:RDFSource
59
60
  def self.rdf_source? response
60
- container?(response) || Array(links(response)["type"]).include?(Ldp.rdf_source)
61
+ container?(response) || Array(links(response)[TYPE]).include?(Ldp.rdf_source)
61
62
  end
62
63
 
63
64
  def dup
64
65
  super.tap do |new_resp|
65
66
  new_resp.send(:extend, Ldp::Response)
66
- if ::RUBY_VERSION < '2.0'
67
- new_resp.send(:remove_instance_variable, :@graph)
68
- else
69
- new_resp.remove_instance_variable(:@graph)
67
+ unless new_resp.instance_variable_get(:@graph).nil?
68
+ if ::RUBY_VERSION < '2.0'
69
+ new_resp.send(:remove_instance_variable, :@graph)
70
+ else
71
+ new_resp.remove_instance_variable(:@graph)
72
+ end
70
73
  end
71
74
  end
72
75
  end
@@ -96,7 +99,7 @@ module Ldp
96
99
  end
97
100
 
98
101
  def preferences
99
- Ldp::Resource.applied_preferences(headers["Preference-Applied"])
102
+ Ldp::Resource.applied_preferences(headers['Preference-Applied'.freeze])
100
103
  end
101
104
  ##
102
105
  # Get the subject for the response
@@ -138,7 +141,7 @@ module Ldp
138
141
  ##
139
142
  # Extract the ETag for the resource
140
143
  def etag
141
- @etag ||= headers['ETag']
144
+ @etag ||= headers['ETag'.freeze]
142
145
  end
143
146
 
144
147
  def etag=(val)
@@ -148,7 +151,7 @@ module Ldp
148
151
  ##
149
152
  # Extract the last modified header for the resource
150
153
  def last_modified
151
- @last_modified ||= headers['Last-Modified']
154
+ @last_modified ||= headers['Last-Modified'.freeze]
152
155
  end
153
156
 
154
157
  def last_modified=(val)
@@ -158,17 +161,19 @@ module Ldp
158
161
  ##
159
162
  # Extract the Link: rel="type" headers for the resource
160
163
  def types
161
- Array(links["type"])
164
+ Array(links[TYPE])
162
165
  end
163
-
166
+
167
+ RETURN = 'return'.freeze
168
+
164
169
  def includes? preference
165
170
  key = Ldp.send("prefer_#{preference}") if Ldp.respond_to("prefer_#{preference}")
166
171
  key ||= preference
167
- preferences["return"][:includes].include?(key) || !preferences["return"][:omits].include?(key)
172
+ preferences[RETURN][:includes].include?(key) || !preferences["return"][:omits].include?(key)
168
173
  end
169
-
174
+
170
175
  def minimal?
171
- preferences["return"][:value] == "minimal"
176
+ preferences[RETURN][:value] == "minimal"
172
177
  end
173
178
  end
174
179
  end
@@ -1,3 +1,3 @@
1
1
  module Ldp
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -19,29 +19,44 @@ describe Ldp::Response do
19
19
  end
20
20
 
21
21
  describe "#dup" do
22
- let(:simple_container_graph) { "<> a <http://www.w3.org/ns/ldp#Container> ." }
23
- let(:link) { ["<http://www.w3.org/ns/ldp#Resource>;rel=\"type\"","<http://www.w3.org/ns/ldp#BasicContainer>;rel=\"type\""] }
24
-
22
+ let(:mock_conn) { Faraday.new { |builder| builder.adapter :test, conn_stubs } }
23
+ let(:client) { Ldp::Client.new mock_conn }
24
+ let(:raw_response) { client.get "a_container" }
25
25
  let(:conn_stubs) do
26
26
  Faraday::Adapter::Test::Stubs.new do |stub|
27
- stub.get('/a_container') { [200, {"Link" => link}, simple_container_graph] }
27
+ stub.get('/a_container') { [200, {"Link" => link}, body] }
28
28
  end
29
29
  end
30
-
31
- let(:mock_conn) { Faraday.new { |builder| builder.adapter :test, conn_stubs } }
32
- let(:client) { Ldp::Client.new mock_conn }
33
- let(:raw_response) { client.get "a_container" }
34
-
35
30
  let(:response) { Ldp::Response.wrap mock_client, raw_response }
31
+
36
32
  subject { response.dup }
37
- it { is_expected.to respond_to :links }
38
33
 
39
- it "should not have duplicated the graph" do
40
- expect(response.graph.object_id).not_to eq subject.graph.object_id
34
+ context "for a container resource" do
35
+ let(:body) { "<> a <http://www.w3.org/ns/ldp#Container> ." }
36
+ let(:link) { ["<http://www.w3.org/ns/ldp#Resource>;rel=\"type\"","<http://www.w3.org/ns/ldp#BasicContainer>;rel=\"type\""] }
37
+ it { is_expected.to respond_to :links }
38
+
39
+ it "should not have duplicated the graph" do
40
+ expect(response.graph.object_id).not_to eq subject.graph.object_id
41
+ end
42
+
43
+ it "should have duplicated the body" do
44
+ expect(response.body.object_id).to eq subject.body.object_id
45
+ end
41
46
  end
42
47
 
43
- it "should have duplicated the body" do
44
- expect(response.body.object_id).to eq subject.body.object_id
48
+ context "for a non-rdf resource" do
49
+ let(:body) { "This is only a test" }
50
+ let(:link) { ["<http://www.w3.org/ns/ldp#Resource>;rel=\"type\"","<http://www.w3.org/ns/ldp#NonRDFSource>;rel=\"type\""] }
51
+ it { is_expected.to respond_to :links }
52
+
53
+ it "should not have a graph" do
54
+ expect(response.instance_variable_get(:@graph)).to be_nil
55
+ end
56
+
57
+ it "should have duplicated the body" do
58
+ expect(response.body.object_id).to eq subject.body.object_id
59
+ end
45
60
  end
46
61
  end
47
62
 
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.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-23 00:00:00.000000000 Z
11
+ date: 2015-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday