class Nanoc::RuleDSL::RuleMemoryCalculator
Calculates rule memories for objects that can be run through a rule (item representations and layouts).
@api private
Attributes
rules_collection[RW]
@api private
Public Class Methods
new(site:, rules_collection:)
click to toggle source
@param [Nanoc::Int::Site] site @param [Nanoc::RuleDSL::RulesCollection] #rules_collection
# File lib/nanoc/rule_dsl/rule_memory_calculator.rb, line 20 def initialize(site,, rules_collection)) @site = site @rules_collection = rules_collection end
Public Instance Methods
[](obj)
click to toggle source
@param [#reference] obj
@return [Nanoc::Int::RuleMemory]
# File lib/nanoc/rule_dsl/rule_memory_calculator.rb, line 28 def [](obj) # FIXME: Remove this obj = obj.unwrap if obj.respond_to?(:unwrap) case obj when Nanoc::Int::ItemRep new_rule_memory_for_rep(obj) when Nanoc::Int::Layout new_rule_memory_for_layout(obj) else raise UnsupportedObjectTypeException.new(obj) end end
new_rule_memory_for_layout(layout)
click to toggle source
@param [Nanoc::Int::Layout] layout
@return [Nanoc::Int::RuleMemory]
# File lib/nanoc/rule_dsl/rule_memory_calculator.rb, line 81 def new_rule_memory_for_layout(layout) res = @rules_collection.filter_for_layout(layout) # FIXME: what if res is nil? Nanoc::Int::RuleMemory.new(layout).tap do |rm| rm.add_filter(res[0], res[1]) end end
new_rule_memory_for_rep(rep)
click to toggle source
@param [Nanoc::Int::ItemRep] rep The item representation to get the rule
memory for
@return [Nanoc::Int::RuleMemory]
# File lib/nanoc/rule_dsl/rule_memory_calculator.rb, line 59 def new_rule_memory_for_rep(rep) # FIXME: What if #compilation_rule_for returns nil? executor = Nanoc::RuleDSL::RecordingExecutor.new(rep, @rules_collection, @site) rule = @rules_collection.compilation_rule_for(rep) executor.snapshot(rep, :raw) executor.snapshot(rep, :pre, final: false) rule.apply_to(rep, executor: executor, site: @site, view_context: nil) if executor.rule_memory.any_layouts? executor.snapshot(rep, :post) end unless executor.rule_memory.snapshot_actions.any? { |sa| sa.snapshot_name == :last } executor.snapshot(rep, :last) end executor.rule_memory end
snapshots_defs_for(rep)
click to toggle source
@param [Nanoc::Int::ItemRep] rep The item representation for which to fetch
the list of snapshots
@return [Array] 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
# File lib/nanoc/rule_dsl/rule_memory_calculator.rb, line 49 def snapshots_defs_for(rep) self[rep].snapshot_actions.map do |a| Nanoc::Int::SnapshotDef.new(a.snapshot_name, a.final?) end end