iglu-ruby-client 0.2.0.beta.3 → 0.2.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/iglu-client/resolver.rb +17 -18
 - data/lib/iglu-client/version.rb +1 -1
 - metadata +6 -6
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 0a74ac41f7b9da9975017fb31119063de09b60774cdeb5c8ecf5cddb2f45471c
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 63f2aaece15b6870a525bf590027b5a8ee6dd88d24c879ef0b63da55e7409ba9
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2e7c12dc0b4e03501ce858a452690a318b5219f7b3bfac236696ee5211b102953d7648ca59645ec7ec1152a9defbf2373a162b8b8f4d6e3d538dd0cd8621f3c6
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 0e0d59c3256592091df824ab8ab30e1249dbe30808ba9c8769ace1a9bf05f98df42974efa85bdb7af3861915b7c89067cf489e5602f37e6ac234e5a34cd5511a
         
     | 
    
        data/lib/iglu-client/resolver.rb
    CHANGED
    
    | 
         @@ -18,21 +18,35 @@ module Iglu 
     | 
|
| 
       18 
18 
     | 
    
         
             
              class Resolver
         
     | 
| 
       19 
19 
     | 
    
         
             
                attr_reader :registries, :cache, :cacheTtl
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
                def initialize(registries, cacheTtl= 
     | 
| 
      
 21 
     | 
    
         
            +
                def initialize(registries, cacheTtl=nil)
         
     | 
| 
       22 
22 
     | 
    
         
             
                  @registries = registries.unshift(Registries.bootstrap)
         
     | 
| 
       23 
23 
     | 
    
         
             
                  @cache = Hash.new
         
     | 
| 
       24 
     | 
    
         
            -
                  @cacheTtl = cacheTtl 
     | 
| 
      
 24 
     | 
    
         
            +
                  @cacheTtl = cacheTtl
         
     | 
| 
       25 
25 
     | 
    
         
             
                end
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
                # Lookup schema in cache or try to fetch
         
     | 
| 
       28 
28 
     | 
    
         
             
                def lookup_schema(schema_key)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  lookup_time = Time.now.getutc
         
     | 
| 
       29 
30 
     | 
    
         
             
                  if schema_key.is_a?(String)
         
     | 
| 
       30 
31 
     | 
    
         
             
                    schema_key = SchemaKey.parse_key(schema_key)
         
     | 
| 
       31 
32 
     | 
    
         
             
                  end
         
     | 
| 
       32 
33 
     | 
    
         
             
                  failures = []
         
     | 
| 
       33 
34 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                  fetch_time = Time.now.getutc
         
     | 
| 
       35 
35 
     | 
    
         
             
                  cache_result = @cache[schema_key]
         
     | 
| 
      
 36 
     | 
    
         
            +
                  if not cache_result.nil?
         
     | 
| 
      
 37 
     | 
    
         
            +
                    if not @cacheTtl.nil?
         
     | 
| 
      
 38 
     | 
    
         
            +
                      store_time = cache_result[1]
         
     | 
| 
      
 39 
     | 
    
         
            +
                      time_diff = (lookup_time - store_time).round
         
     | 
| 
      
 40 
     | 
    
         
            +
                      if time_diff >= @cacheTtl
         
     | 
| 
      
 41 
     | 
    
         
            +
                        @cache.delete(schema_key)
         
     | 
| 
      
 42 
     | 
    
         
            +
                        cache_result = nil
         
     | 
| 
      
 43 
     | 
    
         
            +
                      else
         
     | 
| 
      
 44 
     | 
    
         
            +
                        return cache_result[0]
         
     | 
| 
      
 45 
     | 
    
         
            +
                      end
         
     | 
| 
      
 46 
     | 
    
         
            +
                    else
         
     | 
| 
      
 47 
     | 
    
         
            +
                      return cache_result[0]
         
     | 
| 
      
 48 
     | 
    
         
            +
                    end
         
     | 
| 
      
 49 
     | 
    
         
            +
                  end
         
     | 
| 
       36 
50 
     | 
    
         | 
| 
       37 
51 
     | 
    
         
             
                  if cache_result.nil?          # Fetch from every registry
         
     | 
| 
       38 
52 
     | 
    
         
             
                    for registry in prioritize_repos(schema_key, @registries) do
         
     | 
| 
         @@ -56,21 +70,6 @@ module Iglu 
     | 
|
| 
       56 
70 
     | 
    
         
             
                      @cache[schema_key] = [lookup_result, store_time]
         
     | 
| 
       57 
71 
     | 
    
         
             
                      lookup_result
         
     | 
| 
       58 
72 
     | 
    
         
             
                    end
         
     | 
| 
       59 
     | 
    
         
            -
                  else
         
     | 
| 
       60 
     | 
    
         
            -
                    if cache_result.is_a?(Registries::ResolverError)
         
     | 
| 
       61 
     | 
    
         
            -
                      raise cache_result
         
     | 
| 
       62 
     | 
    
         
            -
                    else
         
     | 
| 
       63 
     | 
    
         
            -
                      if cache_result.is_a? (Array)
         
     | 
| 
       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]
         
     | 
| 
       70 
     | 
    
         
            -
                      else # backward compliance
         
     | 
| 
       71 
     | 
    
         
            -
                          cache_result
         
     | 
| 
       72 
     | 
    
         
            -
                      end
         
     | 
| 
       73 
     | 
    
         
            -
                    end
         
     | 
| 
       74 
73 
     | 
    
         
             
                  end
         
     | 
| 
       75 
74 
     | 
    
         
             
                end
         
     | 
| 
       76 
75 
     | 
    
         | 
    
        data/lib/iglu-client/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: iglu-ruby-client
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.2.0 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Anton Parkhomenko
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2017-11- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-11-09 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: httparty
         
     | 
| 
         @@ -98,15 +98,15 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       98 
98 
     | 
    
         
             
              requirements:
         
     | 
| 
       99 
99 
     | 
    
         
             
              - - ">="
         
     | 
| 
       100 
100 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       101 
     | 
    
         
            -
                  version: 2. 
     | 
| 
      
 101 
     | 
    
         
            +
                  version: 2.1.10
         
     | 
| 
       102 
102 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       103 
103 
     | 
    
         
             
              requirements:
         
     | 
| 
       104 
     | 
    
         
            -
              - - " 
     | 
| 
      
 104 
     | 
    
         
            +
              - - ">="
         
     | 
| 
       105 
105 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       106 
     | 
    
         
            -
                  version:  
     | 
| 
      
 106 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
       107 
107 
     | 
    
         
             
            requirements: []
         
     | 
| 
       108 
108 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       109 
     | 
    
         
            -
            rubygems_version: 2.7. 
     | 
| 
      
 109 
     | 
    
         
            +
            rubygems_version: 2.7.2
         
     | 
| 
       110 
110 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       111 
111 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       112 
112 
     | 
    
         
             
            summary: A Ruby client for Iglu
         
     |