Class: TestTrack::Remote::SplitRegistry

Inherits:
Object
  • Object
show all
Includes:
TestTrack::RemoteModel
Defined in:
app/models/test_track/remote/split_registry.rb

Constant Summary collapse

CACHE_KEY =
'test_track_split_registry'.freeze

Class Method Summary collapse

Class Method Details

.fake_instance_attributes(_) ⇒ Object



9
10
11
# File 'app/models/test_track/remote/split_registry.rb', line 9

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

.instanceObject



13
14
15
16
17
18
19
20
# File 'app/models/test_track/remote/split_registry.rb', line 13

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

.resetObject



22
23
24
# File 'app/models/test_track/remote/split_registry.rb', line 22

def reset
  Rails.cache.delete(CACHE_KEY)
end

.to_hashObject



26
27
28
29
30
31
32
33
34
35
# File 'app/models/test_track/remote/split_registry.rb', line 26

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