Class: Middleman::Presentation::Cache
- Inherits:
-
Object
- Object
- Middleman::Presentation::Cache
- Includes:
- Enumerable
- Defined in:
- lib/middleman-presentation-core/cache.rb
Overview
Cache for objects
It can be used to run ‘block’ on ‘#map` only if new objects have been added.
Instance Method Summary collapse
- #add(obj) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(store: []) ⇒ Cache
constructor
A new instance of Cache.
- #mark_dirty ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(store: []) ⇒ Cache
Returns a new instance of Cache.
18 19 20 21 |
# File 'lib/middleman-presentation-core/cache.rb', line 18 def initialize(store: []) @store = store @clean = true end |
Instance Method Details
#add(obj) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/middleman-presentation-core/cache.rb', line 23 def add(obj) store << obj self.clean = false self end |
#each(&block) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/middleman-presentation-core/cache.rb', line 36 def each(&block) return if clean self.clean = true store.each(&block) end |
#mark_dirty ⇒ Object
30 31 32 33 34 |
# File 'lib/middleman-presentation-core/cache.rb', line 30 def mark_dirty self.clean = false self end |
#to_a ⇒ Object
44 45 46 |
# File 'lib/middleman-presentation-core/cache.rb', line 44 def to_a store.to_a end |