Class: Aranea::Failure::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/aranea/failure_repository.rb

Overview

TODO: Actually implement Repository pattern, dependency injection and all. As is we only support sharing between multiple instances if Rails.cache exists and does

Constant Summary collapse

KEY =
"aranea_current_failure"

Class Method Summary collapse

Class Method Details

.cacheObject



78
79
80
# File 'lib/aranea/failure_repository.rb', line 78

def cache
  @cache ||= rails_cache || memory_store
end

.clearObject



74
75
76
# File 'lib/aranea/failure_repository.rb', line 74

def clear
  cache.delete(KEY)
end

.getObject



70
71
72
# File 'lib/aranea/failure_repository.rb', line 70

def get
  cache.read(KEY)
end

.memory_storeObject



86
87
88
89
# File 'lib/aranea/failure_repository.rb', line 86

def memory_store
  require "active_support/cache"
  ActiveSupport::Cache::MemoryStore.new
end

.rails_cacheObject



82
83
84
# File 'lib/aranea/failure_repository.rb', line 82

def rails_cache
  defined?(Rails.cache) && Rails.cache
end

.store(failure, lifespan) ⇒ Object



65
66
67
68
# File 'lib/aranea/failure_repository.rb', line 65

def store(failure, lifespan)
  failure.expiration_date = Time.now + lifespan
  cache.write(KEY, failure, expires_in: lifespan)
end