tripod 0.12.0 → 0.13.0
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 +4 -4
- data/lib/tripod.rb +3 -0
- data/lib/tripod/fields.rb +29 -8
- data/lib/tripod/sparql_client.rb +3 -2
- data/lib/tripod/streaming.rb +9 -2
- data/lib/tripod/version.rb +1 -1
- data/spec/tripod/fields_spec.rb +72 -1
- data/tripod.gemspec +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67821ecb6a48f3ebf994b42e4a97b4484d70659e
|
4
|
+
data.tar.gz: 641593641f0efbcd459b6747cd635a0132f7254d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adc59ed6b6e5b72ceea3e5453ba45ee1b58f4e93a98e1197d2a18b38137a525d9944c35648d062dce47efa98061e991cc3a595b104b9cf3afad4ad0822cee57d
|
7
|
+
data.tar.gz: 8b5e6f4a90b66b9d60963f325d3cd05c9d1370b37194cdc14b9aa8a072256553db7e3712b4170858550c0e23e3ace2ccb3af8ed7688bbfcd58abe3a4e63db91b
|
data/lib/tripod.rb
CHANGED
data/lib/tripod/fields.rb
CHANGED
@@ -5,9 +5,15 @@ require "tripod/fields/standard"
|
|
5
5
|
module Tripod::Fields
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
-
included
|
9
|
-
|
10
|
-
|
8
|
+
def self.included(base)
|
9
|
+
base.instance_eval do
|
10
|
+
@fields ||= {}
|
11
|
+
end
|
12
|
+
base.extend(ClassMethods)
|
13
|
+
end
|
14
|
+
|
15
|
+
def fields
|
16
|
+
self.class.fields
|
11
17
|
end
|
12
18
|
|
13
19
|
module ClassMethods
|
@@ -37,7 +43,7 @@ module Tripod::Fields
|
|
37
43
|
#
|
38
44
|
# @return [ Field ] The generated field
|
39
45
|
def field(name, predicate, options = {})
|
40
|
-
|
46
|
+
@fields ||= {}
|
41
47
|
add_field(name, predicate, options)
|
42
48
|
end
|
43
49
|
|
@@ -48,13 +54,27 @@ module Tripod::Fields
|
|
48
54
|
#
|
49
55
|
# @param [ Symbol ] name The name of the field.
|
50
56
|
def get_field(name)
|
51
|
-
|
57
|
+
@fields ||= {}
|
58
|
+
field = fields[name]
|
52
59
|
raise Tripod::Errors::FieldNotPresent.new unless field
|
53
60
|
field
|
54
61
|
end
|
55
62
|
|
63
|
+
# Return all of the fields on a +Resource+ in a manner that
|
64
|
+
# respects Ruby's inheritance rules. i.e. subclass fields should
|
65
|
+
# override superclass fields with the same
|
66
|
+
def fields
|
67
|
+
tripod_superclasses.map { |c| c.instance_variable_get(:@fields) }.reduce do |acc,class_fields|
|
68
|
+
class_fields.merge(acc)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
56
72
|
protected
|
57
73
|
|
74
|
+
def tripod_superclasses
|
75
|
+
self.ancestors.select { |a| a.class == Class && a.respond_to?(:fields)}
|
76
|
+
end
|
77
|
+
|
58
78
|
# Define a field attribute for the +Resource+.
|
59
79
|
#
|
60
80
|
# @example Set the field.
|
@@ -66,7 +86,8 @@ module Tripod::Fields
|
|
66
86
|
def add_field(name, predicate, options = {})
|
67
87
|
# create a field object and store it in our hash
|
68
88
|
field = field_for(name, predicate, options)
|
69
|
-
fields
|
89
|
+
@fields ||= {}
|
90
|
+
@fields[name] = field
|
70
91
|
|
71
92
|
# set up the accessors for the fields
|
72
93
|
create_accessors(name, name, options)
|
@@ -90,7 +111,7 @@ module Tripod::Fields
|
|
90
111
|
# @param [ Symbol ] meth The name of the accessor.
|
91
112
|
# @param [ Hash ] options The options.
|
92
113
|
def create_accessors(name, meth, options = {})
|
93
|
-
field = fields[name]
|
114
|
+
field = @fields[name]
|
94
115
|
|
95
116
|
create_field_getter(name, meth, field)
|
96
117
|
create_field_setter(name, meth, field)
|
@@ -148,7 +169,7 @@ module Tripod::Fields
|
|
148
169
|
end
|
149
170
|
end
|
150
171
|
|
151
|
-
|
172
|
+
# Include the field methods as a module, so they can be overridden.
|
152
173
|
#
|
153
174
|
# @example Include the fields.
|
154
175
|
# Person.generated_methods
|
data/lib/tripod/sparql_client.rb
CHANGED
@@ -14,13 +14,14 @@ module Tripod::SparqlClient
|
|
14
14
|
# @param [ String ] accept_header The accept header to send with the request
|
15
15
|
# @param [ Hash ] any extra params to send with the request
|
16
16
|
# @return [ RestClient::Response ]
|
17
|
-
def self.query(sparql, accept_header, extra_params={}, response_limit_bytes = :default)
|
17
|
+
def self.query(sparql, accept_header, extra_params={}, response_limit_bytes = :default, extra_headers = {})
|
18
18
|
|
19
19
|
non_sparql_params = (Tripod.extra_endpoint_params).merge(extra_params)
|
20
20
|
params_hash = {:query => sparql}.merge(non_sparql_params)
|
21
21
|
params = self.to_query(params_hash)
|
22
22
|
request_url = Tripod.query_endpoint
|
23
|
-
|
23
|
+
extra_headers.merge!(Tripod.extra_endpoint_headers)
|
24
|
+
streaming_opts = {:accept => accept_header, :timeout_seconds => Tripod.timeout_seconds, :extra_headers => extra_headers}
|
24
25
|
streaming_opts.merge!(_response_limit_options(response_limit_bytes)) if Tripod.response_limit_bytes
|
25
26
|
|
26
27
|
# Hash.to_query from active support core extensions
|
data/lib/tripod/streaming.rb
CHANGED
@@ -11,10 +11,17 @@ module Tripod
|
|
11
11
|
# :response_limit_bytes = nil
|
12
12
|
def self.get_data(request_url, payload, opts={})
|
13
13
|
|
14
|
-
accept = opts[:accept]
|
14
|
+
accept = opts[:accept]
|
15
15
|
timeout_in_seconds = opts[:timeout_seconds] || 10
|
16
16
|
limit_in_bytes = opts[:response_limit_bytes]
|
17
17
|
|
18
|
+
# set request headers
|
19
|
+
headers = opts[:extra_headers] || {}
|
20
|
+
|
21
|
+
# if explicit accept option is given, set it in the headers (and overwrite any existing value in the extra_headers map)
|
22
|
+
# if none is given accept */*
|
23
|
+
headers['Accept'] = accept || headers['Accept'] || '*/*'
|
24
|
+
|
18
25
|
uri = URI(request_url)
|
19
26
|
|
20
27
|
http = Net::HTTP.new(uri.host, uri.port)
|
@@ -27,7 +34,7 @@ module Tripod
|
|
27
34
|
response = StringIO.new
|
28
35
|
|
29
36
|
begin
|
30
|
-
http.request_post(uri.request_uri, payload,
|
37
|
+
http.request_post(uri.request_uri, payload, headers) do |res|
|
31
38
|
|
32
39
|
response_duration = Time.now - request_start_time if Tripod.logger.debug?
|
33
40
|
|
data/lib/tripod/version.rb
CHANGED
data/spec/tripod/fields_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Tripod::Fields do
|
4
|
-
|
5
4
|
describe ".field" do
|
6
5
|
|
7
6
|
let(:barry) do
|
@@ -50,3 +49,75 @@ describe Tripod::Fields do
|
|
50
49
|
end
|
51
50
|
end
|
52
51
|
end
|
52
|
+
|
53
|
+
module Spec
|
54
|
+
module Tripod
|
55
|
+
module Inheritance
|
56
|
+
BASE_PREDICATE = RDF::URI.new("http://base/predicate/overriden/from/SubSub/up")
|
57
|
+
BASE_PREDICATE_OVERIDE = RDF::URI.new("http://overide/base/predicate")
|
58
|
+
|
59
|
+
ANOTHER_PREDICATE = RDF::RDFS::label
|
60
|
+
|
61
|
+
class Base
|
62
|
+
include ::Tripod::Resource
|
63
|
+
field :inherited, BASE_PREDICATE
|
64
|
+
end
|
65
|
+
|
66
|
+
class Sub < Base
|
67
|
+
field :bar, ANOTHER_PREDICATE
|
68
|
+
# expects inerited to be ANOTHER_PREDICATE
|
69
|
+
end
|
70
|
+
|
71
|
+
class SubSub < Sub
|
72
|
+
field :inherited, BASE_PREDICATE_OVERIDE
|
73
|
+
end
|
74
|
+
|
75
|
+
class SubSubSub < SubSub
|
76
|
+
# defines no new fields, used to test no NullPointerExceptions
|
77
|
+
# etc on classes that don't define fields.
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'inheritance' do
|
81
|
+
describe Base do
|
82
|
+
subject(:base) { Base }
|
83
|
+
|
84
|
+
it "does not inhert fields from subclasses" do
|
85
|
+
expect(base.fields[:bar]).to be_nil
|
86
|
+
end
|
87
|
+
|
88
|
+
it "defines the :inherited field" do
|
89
|
+
inherited_field = base.fields[:inherited]
|
90
|
+
expect(inherited_field.predicate).to eq(BASE_PREDICATE)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe Sub do
|
95
|
+
subject(:inherited) { Sub.get_field(:inherited) }
|
96
|
+
it "does not redefine :inherited field" do
|
97
|
+
expect(inherited.predicate).to eq(BASE_PREDICATE)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe SubSub do
|
102
|
+
subject(:inherited) { SubSub.get_field(:inherited) }
|
103
|
+
|
104
|
+
it "overrides the :inherited field" do
|
105
|
+
expect(inherited.predicate).to eq(BASE_PREDICATE_OVERIDE)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe SubSubSub do
|
110
|
+
it "inherits the :bar field from Sub" do
|
111
|
+
bar = SubSubSub.get_field(:bar)
|
112
|
+
expect(bar.predicate).to eq(ANOTHER_PREDICATE)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "overrides the :inherited field in Base with the value from SubSub" do
|
116
|
+
inherited = SubSubSub.get_field(:inherited)
|
117
|
+
expect(inherited.predicate).to eq(BASE_PREDICATE_OVERIDE)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/tripod.gemspec
CHANGED
@@ -13,6 +13,7 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
14
|
gem.name = "tripod"
|
15
15
|
gem.require_paths = ["lib"]
|
16
|
+
gem.license = 'MIT'
|
16
17
|
gem.version = Tripod::VERSION
|
17
18
|
|
18
19
|
gem.required_rubygems_version = ">= 1.3.6"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tripod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ric Roberts
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-06-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|
@@ -283,7 +283,8 @@ files:
|
|
283
283
|
- spec/tripod/validations/is_url_spec.rb
|
284
284
|
- tripod.gemspec
|
285
285
|
homepage: http://github.com/Swirrl/tripod
|
286
|
-
licenses:
|
286
|
+
licenses:
|
287
|
+
- MIT
|
287
288
|
metadata: {}
|
288
289
|
post_install_message:
|
289
290
|
rdoc_options: []
|