iglu-ruby-client 0.2.0.beta.2 → 0.2.0.beta.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/iglu-client/resolver.rb +11 -9
- data/lib/iglu-client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 639804d0a0d0e3000ebdf016eb18cfe82de1a5bd4fccf14e6c4fadf427fff099
|
4
|
+
data.tar.gz: 693980d18aebd691e106cf1140a01a906fbf467d69ae34196a2cc74e878713da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39996ef92d933d8b9d47e21df020af4287edc519ab7c5f9546cfea38bb304c94f076760d284b9993e6d2aaa72da35faa7a40d90b12f3fb5436f1c471c304f27e
|
7
|
+
data.tar.gz: d8721692049d4780e3d1331003c885e45495cf0dc298bee52160ec785d91042005429d74107d6447e5c5c57301c4a9296f487b42c5076d6f89799418ad7cd9a4
|
data/lib/iglu-client/resolver.rb
CHANGED
@@ -16,12 +16,12 @@ module Iglu
|
|
16
16
|
|
17
17
|
# Iglu Client. Able to fetch schemas only from Iglu Central
|
18
18
|
class Resolver
|
19
|
-
attr_reader :registries, :cache, :
|
19
|
+
attr_reader :registries, :cache, :cacheTtl
|
20
20
|
|
21
|
-
def initialize(registries)
|
21
|
+
def initialize(registries, cacheTtl=60)
|
22
22
|
@registries = registries.unshift(Registries.bootstrap)
|
23
23
|
@cache = Hash.new
|
24
|
-
@
|
24
|
+
@cacheTtl = cacheTtl.nil? ? 60 : cacheTtl
|
25
25
|
end
|
26
26
|
|
27
27
|
# Lookup schema in cache or try to fetch
|
@@ -61,10 +61,12 @@ module Iglu
|
|
61
61
|
raise cache_result
|
62
62
|
else
|
63
63
|
if cache_result.is_a? (Array)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
store_time = cache_result[1]
|
65
|
+
time_diff = (fetch_time - store_time).round
|
66
|
+
if time_diff >= @cacheTtl
|
67
|
+
@cache.delete(schema_key)
|
68
|
+
end
|
69
|
+
cache_result[0]
|
68
70
|
else # backward compliance
|
69
71
|
cache_result
|
70
72
|
end
|
@@ -77,9 +79,9 @@ module Iglu
|
|
77
79
|
schema = Registries.bootstrap.lookup_schema(schema_key)
|
78
80
|
data = get_data(json)
|
79
81
|
if JSON::Validator.validate!(schema, data)
|
80
|
-
# cache_size = data[:cacheSize]
|
81
82
|
registries = data[:repositories].map do |registry| parse_registry(registry) end
|
82
|
-
|
83
|
+
cacheTtl = json[:data][:cacheTtl]
|
84
|
+
Resolver.new(registries, cacheTtl)
|
83
85
|
else
|
84
86
|
throw IgluError.new "Invalid resolver configuration"
|
85
87
|
end
|
data/lib/iglu-client/version.rb
CHANGED