Class: Nanoc::Cachebuster::Strategy Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/nanoc/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.

Direct Known Subclasses

Css, Html

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, current_item) ⇒ Strategy

Returns a new instance of Strategy.



39
40
41
# File 'lib/nanoc/cachebuster/strategy.rb', line 39

def initialize(site, current_item)
  @site, @current_item = site, current_item
end

Instance Attribute Details

#current_itemNanoc::Item (readonly)

The Nanoc item we are currently filtering.

Returns:

  • (Nanoc::Item)


37
38
39
# File 'lib/nanoc/cachebuster/strategy.rb', line 37

def current_item
  @current_item
end

#siteNanoc::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.

Returns:

  • (Nanoc::Site)


32
33
34
# File 'lib/nanoc/cachebuster/strategy.rb', line 32

def site
  @site
end

Class Method Details

.for(kind, site, item) ⇒ Object



18
19
20
21
22
# File 'lib/nanoc/cachebuster/strategy.rb', line 18

def self.for(kind, site, item)
  klass = @subclasses[kind]
  raise Nanoc::Cachebuster::NoSuchStrategy.new "No strategy found for #{kind}" unless klass
  klass.new(site, item)
end

.inherited(subclass) ⇒ Object



14
15
16
# File 'lib/nanoc/cachebuster/strategy.rb', line 14

def self.inherited(subclass)
  @subclasses[subclass.to_s.split('::').last.downcase.to_sym] = subclass
end

Instance Method Details

#applyObject

This method is abstract.

Abstract method that subclasses (actual strategies) should implement.

Raises:

  • (Exception)


47
48
49
# File 'lib/nanoc/cachebuster/strategy.rb', line 47

def apply
  raise Exception, 'Must be implemented in a subclass'
end