json-ld 1.1.3.1 → 1.1.4

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: ca0e3cc4b404992e98906955e4f18b6db85b72ad
4
- data.tar.gz: 23742db95aa45683dc15afb31dd5eb0b9d250b3a
3
+ metadata.gz: e160cdefa8e2b74088deae22decfcb6e4676bb1f
4
+ data.tar.gz: 7910c785d852f65ea62214573c53e6aaf07854ad
5
5
  SHA512:
6
- metadata.gz: 39c2c3ab9f3bfda908845ecd2d24af85dda870a7b636079e8e0360e36682a662f3b9e61552542f4fc1b5e3708872b70be915c534e735214d3f3542cc44afa15e
7
- data.tar.gz: b83c14a4a432554db8e87e93f54ab622fa462a30034fdb29a2fad4f2fe344aa0fe21092aa7b6d8e48220570f597a0ec2981af87644d15061a0c345a0507ac11c
6
+ metadata.gz: 945604edd6ddf16aaf768d2e028d71724fd167d182fd997d431e6efc5b11db1aecff8a37d6fa9400b2c16f85a3c2b664ee4a31f3a1b666dfac4b588c94096c4a
7
+ data.tar.gz: 3062bba010e1170ed9626280e346b988d8b5369cece0aba57addcfdc6111ba46326759f0d9c698581657e35b92412a9bc9905f870b39933105879a21b8e5d786
data/README.md CHANGED
@@ -268,7 +268,7 @@ To get a local working copy of the development repository, do:
268
268
  * Don't use hard tabs, and don't leave trailing whitespace on any line.
269
269
  * Do document every method you add using [YARD][] annotations. Read the
270
270
  [tutorial][YARD-GS] or just look at the existing code for examples.
271
- * Don't touch the `.gemspec`, `VERSION` or `AUTHORS` files. If you need to
271
+ * Don't touch the `json-ld.gemspec`, `VERSION` or `AUTHORS` files. If you need to
272
272
  change them, do so on your private branch only.
273
273
  * Do feel free to add yourself to the `CREDITS` file and the corresponding
274
274
  list in the the `README`. Alphabetical order applies.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.3.1
1
+ 1.1.4
@@ -295,6 +295,7 @@ module JSON::LD
295
295
  debug("parse") {"=> provided_context: #{context.inspect}"}
296
296
  when Hash
297
297
  # If context has a @vocab member: if its value is not a valid absolute IRI or null trigger an INVALID_VOCAB_MAPPING error; otherwise set the active context's vocabulary mapping to its value and remove the @vocab member from context.
298
+ context = context.dup # keep from modifying a hash passed as a param
298
299
  {
299
300
  '@base' => :base=,
300
301
  '@language' => :default_language=,
@@ -2,60 +2,59 @@ module JSON::LD
2
2
  # Simple Ruby reflector class to provide native
3
3
  # access to JSON-LD objects
4
4
  class Resource
5
- # @!attribute [r] attributes
5
+ include RDF::Enumerable
6
+
6
7
  # @return [Hash<String => Object] Object representation of resource
7
8
  attr_reader :attributes
8
9
 
9
- # @!attribute [r] id
10
10
  # @return [String] ID of this resource
11
11
  attr_reader :id
12
12
 
13
- # @!attribute [r] context
14
13
  # @return [JSON::LD::Context] Context associated with this resource
15
14
  attr_reader :context
16
15
 
16
+ ##
17
17
  # Is this resource clean (i.e., saved to mongo?)
18
18
  #
19
19
  # @return [Boolean]
20
20
  def clean?; @clean; end
21
21
 
22
+ ##
22
23
  # Is this resource dirty (i.e., not yet saved to mongo?)
23
24
  #
24
25
  # @return [Boolean]
25
26
  def dirty?; !clean?; end
26
-
27
+
28
+ ##
27
29
  # Has this resource been reconciled against a mongo ID?
28
30
  #
29
31
  # @return [Boolean]
30
32
  def reconciled?; @reconciled; end
31
33
 
34
+ ##
32
35
  # Has this resource been resolved so that
33
36
  # all references are to other Resources?
34
37
  #
35
38
  # @return [Boolean]
36
39
  def resolved?; @resolved; end
37
40
 
41
+ ##
38
42
  # Anonymous resources have BNode ids or no schema:url
39
43
  #
40
44
  # @return [Boolean]
41
45
  def anonymous?; @anon; end
42
46
 
47
+ ##
43
48
  # Is this a stub resource, which has not yet been
44
49
  # synched or created within the DB?
45
50
  def stub?; !!@stub; end
46
51
 
52
+ ##
47
53
  # Is this a new resource, which has not yet been
48
54
  # synched or created within the DB?
49
55
  def new?; !!@new; end
50
56
 
51
- # Manage contexts used by resources.
52
- #
53
- # @param [String] ctx
54
- # @return [JSON::LD::Context]
55
- def self.set_context(ctx)
56
- (@@contexts ||= {})[ctx] = JSON::LD::Context.new.parse(ctx)
57
- end
58
-
57
+ ##
59
58
  # A new resource from the parsed graph
60
59
  # @param [Hash{String => Object}] node_definition
61
60
  # @param [Hash{Symbol => Object}] options
@@ -76,8 +75,7 @@ module JSON::LD
76
75
  # This is a stand-in for another resource that has
77
76
  # not yet been retrieved (or created) from Mongo
78
77
  def initialize(node_definition, options = {})
79
- @context_name = options[:context]
80
- @context = self.class.set_context(@context_name)
78
+ @context = options[:context]
81
79
  @clean = options.fetch(:clean, false)
82
80
  @new = options.fetch(:new, true)
83
81
  @reconciled = options.fetch(:reconciled, !@new)
@@ -91,12 +89,14 @@ module JSON::LD
91
89
  @anon = @id.nil? || @id.to_s[0,2] == '_:'
92
90
  end
93
91
 
92
+ ##
94
93
  # Return a hash of this object, suitable for use by for ETag
95
94
  # @return [Fixnum]
96
95
  def hash
97
96
  self.deresolve.hash
98
97
  end
99
98
 
99
+ ##
100
100
  # Reverse resolution of resource attributes.
101
101
  # Just returns `attributes` if
102
102
  # resource is unresolved. Otherwise, replaces `Resource`
@@ -134,6 +134,7 @@ module JSON::LD
134
134
  compacted.delete_if {|k, v| k == '@context'}
135
135
  end
136
136
 
137
+ ##
137
138
  # Serialize to JSON-LD, minus `@context` using
138
139
  # a deresolved version of the attributes
139
140
  #
@@ -143,6 +144,13 @@ module JSON::LD
143
144
  deresolve.to_json(options)
144
145
  end
145
146
 
147
+ ##
148
+ # Enumerate over statements associated with this resource
149
+ def each(&block)
150
+ JSON::LD::API.toRdf(attributes, expandContext: context, &block)
151
+ end
152
+
153
+ ##
146
154
  # Update node references using the provided map.
147
155
  # This replaces node references with Resources,
148
156
  # either stub or instantiated.
@@ -186,29 +194,7 @@ module JSON::LD
186
194
  self
187
195
  end
188
196
 
189
- # Merge resources
190
- # FIXME: If unreconciled or unresolved resources are merged
191
- # against reconciled/resolved resources, they will appear
192
- # to not match, even if they are really the same thing.
193
- #
194
- # @param [Resource] resource
195
- # @return [Resource] self
196
- def merge(resource)
197
- if attributes.neq?(resource.attributes)
198
- resource.attributes.each do |p, v|
199
- next if p == 'id'
200
- if v.nil? or (v.is_a?(Array) and v.empty?)
201
- attributes.delete(p)
202
- else
203
- attributes[p] = v
204
- end
205
- end
206
- @resolved = @clean = false
207
- end
208
- self
209
- end
210
-
211
- #
197
+ ##
212
198
  # Override this method to implement save using
213
199
  # an appropriate storage mechanism.
214
200
  #
@@ -218,12 +204,14 @@ module JSON::LD
218
204
  #
219
205
  # @return [Boolean] true or false if resource not saved
220
206
  def save
221
- raise NotImplemented
207
+ raise NotImplementedError
222
208
  end
223
209
 
210
+ ##
224
211
  # Access individual fields, from subject definition
225
212
  def property(prop_name); @attributes.fetch(prop_name, nil); end
226
213
 
214
+ ##
227
215
  # Access individual fields, from subject definition
228
216
  def method_missing(method, *args)
229
217
  property(method.to_s)
@@ -3,5 +3,75 @@ $:.unshift "."
3
3
  require 'spec_helper'
4
4
 
5
5
  describe JSON::LD::Resource do
6
- it "is pending"
6
+ subject {JSON::LD::Resource.new({'@id' => '_:foo', "http://schema.org/name" => "foo"})}
7
+ describe "#initialize" do
8
+ specify {expect(subject).not_to be_nil}
9
+ specify {expect(subject).to be_a(JSON::LD::Resource)}
10
+ specify {expect(subject).not_to be_clean}
11
+ specify {expect(subject).to be_anonymous}
12
+ specify {expect(subject).to be_dirty}
13
+ specify {expect(subject).to be_new}
14
+ specify {expect(subject).not_to be_resolved}
15
+ specify {expect(subject).not_to be_stub}
16
+ context "schema:name property" do
17
+ specify {expect(subject.property("http://schema.org/name")).to eq "foo"}
18
+ end
19
+
20
+ describe "compacted with context" do
21
+ subject {JSON::LD::Resource.new({'@id' => '_:foo', "http://schema.org/name" => "foo"}, :compact => true, :context => {"@vocab" => "http://schema.org/"})}
22
+ specify {expect(subject).not_to be_nil}
23
+ specify {expect(subject).to be_a(JSON::LD::Resource)}
24
+ specify {expect(subject).not_to be_clean}
25
+ specify {expect(subject).to be_anonymous}
26
+ specify {expect(subject).to be_dirty}
27
+ specify {expect(subject).to be_new}
28
+ specify {expect(subject).not_to be_resolved}
29
+ specify {expect(subject).not_to be_stub}
30
+ its(:name) {should eq "foo"}
31
+ end
32
+ end
33
+
34
+ describe "#deresolve" do
35
+ it "FIXME"
36
+ end
37
+
38
+ describe "#resolve" do
39
+ it "FIXME"
40
+ end
41
+
42
+ describe "#hash" do
43
+ specify {subject.hash.should be_a(Fixnum)}
44
+
45
+ it "returns the hash of the attributes" do
46
+ subject.hash.should == subject.deresolve.hash
47
+ end
48
+ end
49
+
50
+ describe "#to_json" do
51
+ it "has JSON" do
52
+ subject.to_json.should be_a(String)
53
+ JSON.parse(subject.to_json).should be_a(Hash)
54
+ end
55
+ it "has same ID" do
56
+ JSON.parse(subject.to_json)['@id'].should == subject.id
57
+ end
58
+ end
59
+
60
+ describe "#each" do
61
+ specify {expect {|b| subject.each(&b)}.to yield_with_args(RDF::Statement)}
62
+ end
63
+
64
+ describe RDF::Enumerable do
65
+ specify {expect(subject).to be_enumerable}
66
+
67
+ it "initializes a graph" do
68
+ g = RDF::Graph.new << subject
69
+ expect(g.count).to eq 1
70
+ expect(g.objects.first).to eq "foo"
71
+ end
72
+ end
73
+
74
+ describe "#save" do
75
+ specify {expect {subject.save}.to raise_error(NotImplementedError)}
76
+ end
7
77
  end
metadata CHANGED
@@ -1,162 +1,163 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-ld
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3.1
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg Kellogg
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-23 00:00:00.000000000 Z
11
+ date: 2014-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdf
15
- version_requirements: !ruby/object:Gem::Requirement
15
+ requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.1'
20
- requirement: !ruby/object:Gem::Requirement
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
21
23
  requirements:
22
- - - ~>
24
+ - - "~>"
23
25
  - !ruby/object:Gem::Version
24
26
  version: '1.1'
25
- prerelease: false
26
- type: :runtime
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: equivalent-xml
29
- version_requirements: !ruby/object:Gem::Requirement
29
+ requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0.4'
34
- requirement: !ruby/object:Gem::Requirement
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
35
37
  requirements:
36
- - - ~>
38
+ - - "~>"
37
39
  - !ruby/object:Gem::Version
38
40
  version: '0.4'
39
- prerelease: false
40
- type: :development
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: open-uri-cached
43
- version_requirements: !ruby/object:Gem::Requirement
43
+ requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0.0'
48
- - - '>='
48
+ - - ">="
49
49
  - !ruby/object:Gem::Version
50
50
  version: 0.0.5
51
- requirement: !ruby/object:Gem::Requirement
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
52
54
  requirements:
53
- - - ~>
55
+ - - "~>"
54
56
  - !ruby/object:Gem::Version
55
57
  version: '0.0'
56
- - - '>='
58
+ - - ">="
57
59
  - !ruby/object:Gem::Version
58
60
  version: 0.0.5
59
- prerelease: false
60
- type: :development
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: yard
63
- version_requirements: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ~>
66
- - !ruby/object:Gem::Version
67
- version: '0.8'
68
63
  requirement: !ruby/object:Gem::Requirement
69
64
  requirements:
70
- - - ~>
65
+ - - "~>"
71
66
  - !ruby/object:Gem::Version
72
67
  version: '0.8'
73
- prerelease: false
74
68
  type: :development
75
- - !ruby/object:Gem::Dependency
76
- name: rspec
69
+ prerelease: false
77
70
  version_requirements: !ruby/object:Gem::Requirement
78
71
  requirements:
79
- - - ~>
72
+ - - "~>"
80
73
  - !ruby/object:Gem::Version
81
- version: '2.14'
74
+ version: '0.8'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
82
77
  requirement: !ruby/object:Gem::Requirement
83
78
  requirements:
84
- - - ~>
79
+ - - "~>"
85
80
  - !ruby/object:Gem::Version
86
81
  version: '2.14'
87
- prerelease: false
88
82
  type: :development
89
- - !ruby/object:Gem::Dependency
90
- name: rdf-spec
83
+ prerelease: false
91
84
  version_requirements: !ruby/object:Gem::Requirement
92
85
  requirements:
93
- - - ~>
86
+ - - "~>"
94
87
  - !ruby/object:Gem::Version
95
- version: '1.1'
88
+ version: '2.14'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rdf-spec
96
91
  requirement: !ruby/object:Gem::Requirement
97
92
  requirements:
98
- - - ~>
93
+ - - "~>"
99
94
  - !ruby/object:Gem::Version
100
95
  version: '1.1'
101
- prerelease: false
102
96
  type: :development
103
- - !ruby/object:Gem::Dependency
104
- name: rdf-turtle
97
+ prerelease: false
105
98
  version_requirements: !ruby/object:Gem::Requirement
106
99
  requirements:
107
- - - ~>
100
+ - - "~>"
108
101
  - !ruby/object:Gem::Version
109
102
  version: '1.1'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rdf-turtle
110
105
  requirement: !ruby/object:Gem::Requirement
111
106
  requirements:
112
- - - ~>
107
+ - - "~>"
113
108
  - !ruby/object:Gem::Version
114
109
  version: '1.1'
115
- prerelease: false
116
110
  type: :development
117
- - !ruby/object:Gem::Dependency
118
- name: rdf-trig
111
+ prerelease: false
119
112
  version_requirements: !ruby/object:Gem::Requirement
120
113
  requirements:
121
- - - ~>
114
+ - - "~>"
122
115
  - !ruby/object:Gem::Version
123
116
  version: '1.1'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rdf-trig
124
119
  requirement: !ruby/object:Gem::Requirement
125
120
  requirements:
126
- - - ~>
121
+ - - "~>"
127
122
  - !ruby/object:Gem::Version
128
123
  version: '1.1'
129
- prerelease: false
130
124
  type: :development
131
- - !ruby/object:Gem::Dependency
132
- name: rdf-isomorphic
125
+ prerelease: false
133
126
  version_requirements: !ruby/object:Gem::Requirement
134
127
  requirements:
135
- - - ~>
128
+ - - "~>"
136
129
  - !ruby/object:Gem::Version
137
130
  version: '1.1'
131
+ - !ruby/object:Gem::Dependency
132
+ name: rdf-isomorphic
138
133
  requirement: !ruby/object:Gem::Requirement
139
134
  requirements:
140
- - - ~>
135
+ - - "~>"
141
136
  - !ruby/object:Gem::Version
142
137
  version: '1.1'
143
- prerelease: false
144
138
  type: :development
145
- - !ruby/object:Gem::Dependency
146
- name: rdf-xsd
139
+ prerelease: false
147
140
  version_requirements: !ruby/object:Gem::Requirement
148
141
  requirements:
149
- - - ~>
142
+ - - "~>"
150
143
  - !ruby/object:Gem::Version
151
144
  version: '1.1'
145
+ - !ruby/object:Gem::Dependency
146
+ name: rdf-xsd
152
147
  requirement: !ruby/object:Gem::Requirement
153
148
  requirements:
154
- - - ~>
149
+ - - "~>"
155
150
  - !ruby/object:Gem::Version
156
151
  version: '1.1'
157
- prerelease: false
158
152
  type: :development
159
- description: JSON::LD parses and serializes JSON-LD into RDF and implements expansion, compaction and framing API interfaces.
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '1.1'
159
+ description: JSON::LD parses and serializes JSON-LD into RDF and implements expansion,
160
+ compaction and framing API interfaces.
160
161
  email: public-linked-json@w3.org
161
162
  executables:
162
163
  - jsonld
@@ -268,24 +269,24 @@ homepage: http://github.com/ruby-rdf/json-ld
268
269
  licenses:
269
270
  - Public Domain
270
271
  metadata: {}
271
- post_install_message:
272
+ post_install_message:
272
273
  rdoc_options: []
273
274
  require_paths:
274
275
  - lib
275
276
  required_ruby_version: !ruby/object:Gem::Requirement
276
277
  requirements:
277
- - - '>='
278
+ - - ">="
278
279
  - !ruby/object:Gem::Version
279
280
  version: 1.9.2
280
281
  required_rubygems_version: !ruby/object:Gem::Requirement
281
282
  requirements:
282
- - - '>='
283
+ - - ">="
283
284
  - !ruby/object:Gem::Version
284
285
  version: '0'
285
286
  requirements: []
286
287
  rubyforge_project: json-ld
287
288
  rubygems_version: 2.2.2
288
- signing_key:
289
+ signing_key:
289
290
  specification_version: 4
290
291
  summary: JSON-LD reader/writer for Ruby.
291
292
  test_files:
@@ -310,9 +311,9 @@ test_files:
310
311
  - spec/suite_helper.rb
311
312
  - spec/suite_remote_doc_spec.rb
312
313
  - spec/suite_to_rdf_spec.rb
314
+ - spec/support/extensions.rb
313
315
  - spec/to_rdf_spec.rb
314
316
  - spec/writer_spec.rb
315
- - spec/support/extensions.rb
316
317
  - spec/test-files/test-1-automatic.json
317
318
  - spec/test-files/test-1-compacted.json
318
319
  - spec/test-files/test-1-context.json