Sha256: bc1ed786075202fc4fbb326cb725d4e13cb516434147a0882eaf0922e74df619

Contents?: true

Size: 1 KB

Versions: 23

Compression:

Stored size: 1 KB

Contents

# encoding: utf-8

module Nanoc

  # Calculates rule memories for objects that can be run through a rule (item
  # representations and layouts).
  #
  # @api private
  class RuleMemoryCalculator

    extend Nanoc::Memoization

    # @option params [Nanoc::RulesCollection] rules_collection The rules
    #   collection
    def initialize(params={})
      @rules_collection = params[:rules_collection] or
        raise ArgumentError, "Required :rules_collection option is missing"
    end

    # @param [#reference] obj The object to calculate the rule memory for
    #
    # @return [Array] The caluclated rule memory for the given object
    def [](obj)
      result = case obj.type
        when :item_rep
          @rules_collection.new_rule_memory_for_rep(obj)
        when :layout
          @rules_collection.new_rule_memory_for_layout(obj)
        else
          raise RuntimeError,
            "Do not know how to calculate the rule memory for #{obj.inspect}"
      end

      result
    end
    memoize :[]

  end

end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
nanoc-3.6.7 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.6.6 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.6.5 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.6.4 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.6.3 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.6.2 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.6.1 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.6.0 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.5.0 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.5.0b2 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.5.0b1 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.4.3 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.4.2 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.4.1 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.4.0 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.3.7 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.3.6 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.3.5 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.3.4 lib/nanoc/base/compilation/rule_memory_calculator.rb
nanoc-3.3.3 lib/nanoc/base/compilation/rule_memory_calculator.rb