Class: Nanoc::RulesCollection Private
- Inherits:
-
Object
- Object
- Nanoc::RulesCollection
- Extended by:
- Memoization
- Defined in:
- lib/nanoc/base/compilation/rules_collection.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Keeps track of the rules in a site.
Instance Attribute Summary (collapse)
-
- (Array<Nanoc::Rule>) item_compilation_rules
readonly
private
The list of item compilation rules that will be used to compile items.
-
- (Array<Nanoc::Rule>) item_routing_rules
readonly
private
The list of routing rules that will be used to give all items a path.
-
- (Hash) layout_filter_mapping
readonly
private
The hash containing layout-to-filter mapping rules.
-
- (Proc) preprocessor
private
The code block that will be executed after all data is loaded but before the site is compiled.
Instance Method Summary (collapse)
-
- (void) add_item_compilation_rule(rule)
private
Add the given rule to the list of item compilation rules.
-
- (void) add_item_routing_rule(rule)
private
Add the given rule to the list of item routing rules.
-
- (String) checksum
private
The checksum for this object.
-
- (Nanoc::Rule?) compilation_rule_for(rep)
private
Finds the first matching compilation rule for the given item representation.
-
- (Object) dsl
private
Returns the Nanoc::CompilerDSL that should be used for this site.
-
- (Array?) filter_for_layout(layout)
private
Finds the filter name and arguments to use for the given layout.
-
- (RulesCollection) initialize(compiler)
constructor
private
A new instance of RulesCollection.
-
- (Object) inspect
private
-
- (Array) item_compilation_rules_for(item)
private
The list of item compilation rules for the given item.
-
- (void) load
private
Loads this site’s rules.
-
- (Array) make_rule_memory_serializable(rs)
private
Makes the given rule memory serializable by calling
#inspecton the filter arguments, so that objects such as classes and filenames can be serialized. -
- (Array) new_rule_memory_for_layout(layout)
private
The rule memory for the given layout.
-
- (Array) new_rule_memory_for_rep(rep)
private
The rule memory for the given item representation.
-
- (Object) reference
private
Returns an object that can be used for uniquely identifying objects.
-
- (Nanoc::Rule?) routing_rule_for(rep)
private
Finds the first matching routing rule for the given item representation.
-
- (Hash<Symbol, Nanoc::Rule>) routing_rules_for(rep)
private
Returns the list of routing rules that can be applied to the given item representation.
-
- (Nanoc::RuleMemoryCalculator) rule_memory_calculator
private
The rule memory calculator.
-
- (Boolean) rule_memory_differs_for(obj)
private
changed since the last compilation, false otherwise.
-
- (Nanoc::RuleMemoryStore) rule_memory_store
private
The rule memory store.
-
- (Array) snapshots_for(rep)
private
A list of snapshots, represented as arrays where the first element is the snapshot name (a Symbol) and the last element is a Boolean indicating whether the snapshot is final or not.
-
- (void) unload
private
Unloads this site’s rules.
Methods included from Memoization
Constructor Details
- (RulesCollection) initialize(compiler)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RulesCollection
31 32 33 34 35 36 37 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 31 def initialize(compiler) @compiler = compiler @item_compilation_rules = [] @item_routing_rules = [] @layout_filter_mapping = OrderedHash.new end |
Instance Attribute Details
- (Array<Nanoc::Rule>) item_compilation_rules (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The list of item compilation rules that will be used to compile items.
14 15 16 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 14 def item_compilation_rules @item_compilation_rules end |
- (Array<Nanoc::Rule>) item_routing_rules (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The list of routing rules that will be used to give all items a path.
18 19 20 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 18 def item_routing_rules @item_routing_rules end |
- (Hash) layout_filter_mapping (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The hash containing layout-to-filter mapping rules. This hash is ordered: iterating over the hash will happen in insertion order.
24 25 26 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 24 def layout_filter_mapping @layout_filter_mapping end |
- (Proc) preprocessor
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The code block that will be executed after all data is loaded but before the site is compiled
28 29 30 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 28 def preprocessor @preprocessor end |
Instance Method Details
- (void) add_item_compilation_rule(rule)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Add the given rule to the list of item compilation rules.
44 45 46 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 44 def add_item_compilation_rule(rule) @item_compilation_rules << rule end |
- (void) add_item_routing_rule(rule)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Add the given rule to the list of item routing rules.
53 54 55 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 53 def add_item_routing_rule(rule) @item_routing_rules << rule end |
- (String) checksum
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The checksum for this object. If its contents change, the checksum will change as well.
163 164 165 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 163 def checksum @data.checksum end |
- (Nanoc::Rule?) compilation_rule_for(rep)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Finds the first matching compilation rule for the given item representation.
97 98 99 100 101 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 97 def compilation_rule_for(rep) @item_compilation_rules.find do |rule| rule.applicable_to?(rep.item) && rule.rep_name == rep.name end end |
- (Object) dsl
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the Nanoc::CompilerDSL that should be used for this site.
149 150 151 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 149 def dsl Nanoc::CompilerDSL.new(self, @compiler.site.config) end |
- (Array?) filter_for_layout(layout)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Finds the filter name and arguments to use for the given layout.
141 142 143 144 145 146 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 141 def filter_for_layout(layout) @layout_filter_mapping.each_pair do |layout_identifier, filter_name_and_args| return filter_name_and_args if layout.identifier =~ layout_identifier end nil end |
- (Object) inspect
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
167 168 169 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 167 def inspect "<#{self.class}>" end |
- (Array) item_compilation_rules_for(item)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The list of item compilation rules for the given item
61 62 63 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 61 def item_compilation_rules_for(item) @item_compilation_rules.select { |r| r.applicable_to?(item) } end |
- (void) load
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Loads this site’s rules.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 68 def load # Find rules file rules_filenames = [ 'Rules', 'rules', 'Rules.rb', 'rules.rb' ] rules_filename = rules_filenames.find { |f| File.file?(f) } raise Nanoc::Errors::NoRulesFileFound.new if rules_filename.nil? # Get rule data @data = File.read(rules_filename) # Load DSL dsl.instance_eval(@data, "./#{rules_filename}") end |
- (Array) make_rule_memory_serializable(rs)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Makes the given rule memory serializable by calling #inspect on the
filter arguments, so that objects such as classes and filenames can be
serialized.
190 191 192 193 194 195 196 197 198 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 190 def make_rule_memory_serializable(rs) rs.map do |r| if r[0] == :filter [ r[0], r[1], r[2].to_a.map { |a| a.inspect } ] else r end end end |
- (Array) new_rule_memory_for_layout(layout)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The rule memory for the given layout
203 204 205 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 203 def new_rule_memory_for_layout(layout) filter_for_layout(layout) end |
- (Array) new_rule_memory_for_rep(rep)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The rule memory for the given item representation
175 176 177 178 179 180 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 175 def new_rule_memory_for_rep(rep) recording_proxy = rep.to_recording_proxy compilation_rule_for(rep).apply_to(recording_proxy, :compiler => @compiler) recording_proxy.rule_memory << [ :write, rep.path ] make_rule_memory_serializable(recording_proxy.rule_memory) end |
- (Object) reference
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns an object that can be used for uniquely identifying objects.
157 158 159 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 157 def reference :rules end |
- (Nanoc::Rule?) routing_rule_for(rep)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Finds the first matching routing rule for the given item representation.
109 110 111 112 113 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 109 def routing_rule_for(rep) @item_routing_rules.find do |rule| rule.applicable_to?(rep.item) && rule.rep_name == rep.name end end |
- (Hash<Symbol, Nanoc::Rule>) routing_rules_for(rep)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the list of routing rules that can be applied to the given item representation. For each snapshot, the first matching rule will be returned. The result is a hash containing the corresponding rule for each snapshot.
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 123 def routing_rules_for(rep) rules = {} @item_routing_rules.each do |rule| next if !rule.applicable_to?(rep.item) next if rule.rep_name != rep.name next if rules.key?(rule.snapshot_name) rules[rule.snapshot_name] = rule end rules end |
- (Nanoc::RuleMemoryCalculator) rule_memory_calculator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The rule memory calculator
235 236 237 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 235 def rule_memory_calculator @compiler.rule_memory_calculator end |
- (Boolean) rule_memory_differs_for(obj)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
changed since the last compilation, false otherwise
224 225 226 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 224 def rule_memory_differs_for(obj) !rule_memory_store[obj].eql?(rule_memory_calculator[obj]) end |
- (Nanoc::RuleMemoryStore) rule_memory_store
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The rule memory store
230 231 232 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 230 def rule_memory_store @compiler.rule_memory_store end |
- (Array) snapshots_for(rep)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns A list of snapshots, represented as arrays where the first element is the snapshot name (a Symbol) and the last element is a Boolean indicating whether the snapshot is final or not
214 215 216 217 218 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 214 def snapshots_for(rep) new_rule_memory_for_rep(rep).select { |e| e[0] == :snapshot }.map do |e| [ e[1], e[2].fetch(:final) { true } ] end end |
- (void) unload
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Unloads this site’s rules.
84 85 86 87 88 |
# File 'lib/nanoc/base/compilation/rules_collection.rb', line 84 def unload @item_compilation_rules = [] @item_routing_rules = [] @layout_filter_mapping = OrderedHash.new end |