Class: Nanoc3::Cachebuster::Strategy Abstract
- Inherits:
-
Object
- Object
- Nanoc3::Cachebuster::Strategy
- Defined in:
- lib/nanoc3/cachebuster/strategy.rb
Overview
This class is abstract.
The Strategy is a way to deal with an input file. The Cache busting filter will use a strategy to process all references. You may want to use different strategies for different file types.
Instance Attribute Summary collapse
-
#current_item ⇒ Nanoc3::Item
readonly
The Nanoc item we are currently filtering.
-
#site ⇒ Nanoc3::Site
readonly
The current site.
Class Method Summary collapse
Instance Method Summary collapse
-
#apply ⇒ Object
abstract
Abstract method that subclasses (actual strategies) should implement.
-
#initialize(site, current_item) ⇒ Strategy
constructor
A new instance of Strategy.
Constructor Details
#initialize(site, current_item) ⇒ Strategy
Returns a new instance of Strategy.
37 38 39 |
# File 'lib/nanoc3/cachebuster/strategy.rb', line 37 def initialize(site, current_item) @site, @current_item = site, current_item end |
Instance Attribute Details
#current_item ⇒ Nanoc3::Item (readonly)
The Nanoc item we are currently filtering.
35 36 37 |
# File 'lib/nanoc3/cachebuster/strategy.rb', line 35 def current_item @current_item end |
#site ⇒ Nanoc3::Site (readonly)
The current site. We need a reference to that in a strategy, so we can browse through all its items.
This might very well have been just the site#items array, but for future portability we might as well carry the entire site object over.
30 31 32 |
# File 'lib/nanoc3/cachebuster/strategy.rb', line 30 def site @site end |
Class Method Details
.for(kind, site, item) ⇒ Object
16 17 18 19 20 |
# File 'lib/nanoc3/cachebuster/strategy.rb', line 16 def self.for(kind, site, item) klass = @subclasses[kind] raise Nanoc3::Cachebuster::NoSuchStrategy.new "No strategy found for #{kind}" unless klass klass.new(site, item) end |
.inherited(subclass) ⇒ Object
12 13 14 |
# File 'lib/nanoc3/cachebuster/strategy.rb', line 12 def self.inherited(subclass) @subclasses[subclass.to_s.split('::').last.downcase.to_sym] = subclass end |
Instance Method Details
#apply ⇒ Object
This method is abstract.
Abstract method that subclasses (actual strategies) should implement.
45 46 47 |
# File 'lib/nanoc3/cachebuster/strategy.rb', line 45 def apply raise Exception, 'Must be implemented in a subclass' end |