Class: DeadCodeDetector::Storage::MemoryBackend
- Inherits:
-
Object
- Object
- DeadCodeDetector::Storage::MemoryBackend
- Defined in:
- lib/dead_code_detector/storage/memory_backend.rb
Instance Attribute Summary collapse
-
#flush_immediately ⇒ Object
Returns the value of attribute flush_immediately.
-
#pending_deletions ⇒ Object
readonly
Returns the value of attribute pending_deletions.
Instance Method Summary collapse
- #add(key, values) ⇒ Object
- #clear(key) ⇒ Object
- #delete(key, value) ⇒ Object
- #flush ⇒ Object
- #get(key) ⇒ Object
-
#initialize ⇒ MemoryBackend
constructor
A new instance of MemoryBackend.
Constructor Details
#initialize ⇒ MemoryBackend
Returns a new instance of MemoryBackend.
9 10 11 12 |
# File 'lib/dead_code_detector/storage/memory_backend.rb', line 9 def initialize @mapping = Hash.new{|h,k| h[k] = Set.new } @pending_deletions = Hash.new{|h,k| h[k] = Set.new } end |
Instance Attribute Details
#flush_immediately ⇒ Object
Returns the value of attribute flush_immediately.
6 7 8 |
# File 'lib/dead_code_detector/storage/memory_backend.rb', line 6 def flush_immediately @flush_immediately end |
#pending_deletions ⇒ Object (readonly)
Returns the value of attribute pending_deletions.
7 8 9 |
# File 'lib/dead_code_detector/storage/memory_backend.rb', line 7 def pending_deletions @pending_deletions end |
Instance Method Details
#add(key, values) ⇒ Object
18 19 20 |
# File 'lib/dead_code_detector/storage/memory_backend.rb', line 18 def add(key, values) @mapping[key].merge(Array(values)) end |
#clear(key) ⇒ Object
14 15 16 |
# File 'lib/dead_code_detector/storage/memory_backend.rb', line 14 def clear(key) @mapping.delete(key) end |
#delete(key, value) ⇒ Object
30 31 32 33 |
# File 'lib/dead_code_detector/storage/memory_backend.rb', line 30 def delete(key, value) @pending_deletions[key] << value.to_s flush if flush_immediately end |
#flush ⇒ Object
35 36 37 38 39 40 |
# File 'lib/dead_code_detector/storage/memory_backend.rb', line 35 def flush @pending_deletions.each do |key, values| @mapping[key].subtract(values) end @pending_deletions.clear end |
#get(key) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/dead_code_detector/storage/memory_backend.rb', line 22 def get(key) if @pending_deletions.key?(key) @mapping[key] - @pending_deletions[key] else @mapping[key] end end |