Class: Middleman::Presentation::AssetStore
- Inherits:
-
Object
- Object
- Middleman::Presentation::AssetStore
- Includes:
- Enumerable
- Defined in:
- lib/middleman-presentation-core/asset_store.rb
Overview
Store which stores assets
Instance Method Summary collapse
-
#add(asset) ⇒ Object
Add asset.
-
#assets ⇒ Object
All uniq assets.
-
#each(&block) ⇒ Object
Iterate over assets.
-
#find(**args, &block) ⇒ Object
Find asset matching criteria.
-
#find_all(source_path: nil) { ... } ⇒ Object
Find all assets matching criteria.
-
#initialize ⇒ AssetStore
constructor
A new instance of AssetStore.
-
#merge(list_or_store) ⇒ Object
Merge list.
Constructor Details
#initialize ⇒ AssetStore
Returns a new instance of AssetStore.
19 20 21 |
# File 'lib/middleman-presentation-core/asset_store.rb', line 19 def initialize @store = [] end |
Instance Method Details
#add(asset) ⇒ Object
Add asset
24 25 26 27 28 29 30 |
# File 'lib/middleman-presentation-core/asset_store.rb', line 24 def add(asset) if (existing_asset = @store.find { |a| a.source_path == asset.source_path }) existing_asset.merge! asset else store << asset end end |
#assets ⇒ Object
All uniq assets
41 42 43 |
# File 'lib/middleman-presentation-core/asset_store.rb', line 41 def assets store.uniq end |
#each(&block) ⇒ Object
Iterate over assets
46 47 48 |
# File 'lib/middleman-presentation-core/asset_store.rb', line 46 def each(&block) assets.each(&block) end |
#find(**args, &block) ⇒ Object
Find asset matching criteria
68 69 70 |
# File 'lib/middleman-presentation-core/asset_store.rb', line 68 def find(**args, &block) find_all(**args, &block).first end |
#find_all(source_path: nil) { ... } ⇒ Object
Find all assets matching criteria
57 58 59 60 61 62 63 |
# File 'lib/middleman-presentation-core/asset_store.rb', line 57 def find_all(source_path: nil, &block) if block_given? store.select(&block) else store.select { |a| a.source_path == source_path } end end |
#merge(list_or_store) ⇒ Object
Merge list
36 37 38 |
# File 'lib/middleman-presentation-core/asset_store.rb', line 36 def merge(list_or_store) list_or_store.each { |a| add a } end |