Class: RoxClient::RSpec::Cache
- Inherits:
-
Object
- Object
- RoxClient::RSpec::Cache
- Defined in:
- lib/rox-client-rspec/cache.rb
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Cache
constructor
A new instance of Cache.
- #known?(test_result) ⇒ Boolean
- #load ⇒ Object
- #save(test_run) ⇒ Object
- #stale?(test_result) ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Cache
Returns a new instance of Cache.
8 9 10 11 |
# File 'lib/rox-client-rspec/cache.rb', line 8 def initialize = {} @tests = {} @workspace, @server_name, @project_api_id = [:workspace], [:server_name], [:project_api_id] end |
Instance Method Details
#known?(test_result) ⇒ Boolean
36 37 38 |
# File 'lib/rox-client-rspec/cache.rb', line 36 def known? test_result @tests[@project_api_id] && !!@tests[@project_api_id][test_result.key] end |
#load ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rox-client-rspec/cache.rb', line 25 def load validate! @tests = if File.exists? cache_file Oj.load(File.read(cache_file), mode: :strict) rescue {} else {} end self end |
#save(test_run) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rox-client-rspec/cache.rb', line 13 def save test_run validate! @tests = { @project_api_id => @tests[@project_api_id] || {} } test_run.results.each{ |r| @tests[@project_api_id][r.key] = test_result_hash(r) } FileUtils.mkdir_p File.dirname(cache_file) File.open(cache_file, 'w'){ |f| f.write Oj.dump(@tests, mode: :strict) } self end |
#stale?(test_result) ⇒ Boolean
40 41 42 |
# File 'lib/rox-client-rspec/cache.rb', line 40 def stale? test_result @tests[@project_api_id] && test_result_hash(test_result) != @tests[@project_api_id][test_result.key] end |