Sha256: be96dbf398b178a1aa041a915950669e6ec9d5224fd5dacd548fee8694088cb2

Contents?: true

Size: 1.06 KB

Versions: 11

Compression:

Stored size: 1.06 KB

Contents

class TestTrack::Remote::SplitRegistry
  include TestTrack::RemoteModel

  CACHE_KEY = 'test_track_split_registry'.freeze

  collection_path 'api/v3/builds/:build_timestamp/split_registry'

  class << self
    def fake_instance_attributes(_)
      ::TestTrack::Fake::SplitRegistry.instance.to_h
    end

    def instance
      # TODO: FakeableHer needs to make this faking a feature of `get`
      if faked?
        new(fake_instance_attributes(nil))
      else
        get("api/v3/builds/#{TestTrack.build_timestamp}/split_registry")
      end
    end

    def reset
      Rails.cache.delete(CACHE_KEY)
    end

    def to_hash
      if faked?
        instance.attributes.freeze
      else
        fetch_cache { instance.attributes }.freeze
      end
    rescue *TestTrack::SERVER_ERRORS => e
      Rails.logger.error "TestTrack failed to load split registry. #{e}"
      fetch_cache { nil } # cache the missing registry for 5 seconds if we can't get one
    end

    private

    def fetch_cache(&block)
      Rails.cache.fetch(CACHE_KEY, expires_in: 5.seconds, &block)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
test_track_rails_client-7.1.2 app/models/test_track/remote/split_registry.rb
test_track_rails_client-7.1.1 app/models/test_track/remote/split_registry.rb
test_track_rails_client-7.0.0 app/models/test_track/remote/split_registry.rb
test_track_rails_client-6.0.0 app/models/test_track/remote/split_registry.rb
test_track_rails_client-5.0.1 app/models/test_track/remote/split_registry.rb
test_track_rails_client-5.0.0 app/models/test_track/remote/split_registry.rb
test_track_rails_client-4.0.2 app/models/test_track/remote/split_registry.rb
test_track_rails_client-4.0.1 app/models/test_track/remote/split_registry.rb
test_track_rails_client-4.0.0 app/models/test_track/remote/split_registry.rb
test_track_rails_client-4.0.0.rc3 app/models/test_track/remote/split_registry.rb
test_track_rails_client-4.0.0.rc2 app/models/test_track/remote/split_registry.rb