Class: Shark::RSpec::FakeSurveyService::ObjectCache
- Inherits:
-
Object
- Object
- Shark::RSpec::FakeSurveyService::ObjectCache
- Includes:
- Singleton
- Defined in:
- lib/shark/rspec/fake_survey_service/object_cache.rb
Instance Attribute Summary collapse
-
#objects ⇒ Object
Returns the value of attribute objects.
Class Method Summary collapse
Instance Method Summary collapse
- #add(payload) ⇒ Object
- #find(id, type) ⇒ Object
-
#initialize ⇒ ObjectCache
constructor
A new instance of ObjectCache.
- #remove(id, type) ⇒ Object
Constructor Details
#initialize ⇒ ObjectCache
Returns a new instance of ObjectCache.
10 11 12 |
# File 'lib/shark/rspec/fake_survey_service/object_cache.rb', line 10 def initialize @objects = [] end |
Instance Attribute Details
#objects ⇒ Object
Returns the value of attribute objects.
8 9 10 |
# File 'lib/shark/rspec/fake_survey_service/object_cache.rb', line 8 def objects @objects end |
Class Method Details
.clear ⇒ Object
14 15 16 |
# File 'lib/shark/rspec/fake_survey_service/object_cache.rb', line 14 def self.clear instance.objects = [] end |
Instance Method Details
#add(payload) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/shark/rspec/fake_survey_service/object_cache.rb', line 18 def add(payload) payload['id'] = SecureRandom.uuid if payload['id'].blank? objects << payload unless objects.detect { |o| o['id'] == id } payload end |
#find(id, type) ⇒ Object
26 27 28 |
# File 'lib/shark/rspec/fake_survey_service/object_cache.rb', line 26 def find(id, type) objects.detect { |o| o['id'] == id && o['type'] == type } end |
#remove(id, type) ⇒ Object
30 31 32 |
# File 'lib/shark/rspec/fake_survey_service/object_cache.rb', line 30 def remove(id, type) objects.delete_if { |o| o['id'] == id && o['type'] == type } end |