Class: Nanoc::RuleMemoryCalculator Private

Inherits:
Object
  • Object
show all
Extended by:
Memoization
Defined in:
lib/nanoc/base/compilation/rule_memory_calculator.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.

Calculates rule memories for objects that can be run through a rule (item representations and layouts).

Instance Method Summary (collapse)

Methods included from Memoization

memoize

Constructor Details

- (RuleMemoryCalculator) initialize(params = {})

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 RuleMemoryCalculator

Parameters:

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):



15
16
17
18
19
# File 'lib/nanoc/base/compilation/rule_memory_calculator.rb', line 15

def initialize(params = {})
  @rules_collection = params.fetch(:rules_collection) do
    raise ArgumentError, 'Required :rules_collection option is missing'
  end
end

Instance Method Details

- (Array) [](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.

Returns The caluclated rule memory for the given object

Parameters:

  • obj (#reference)

    The object to calculate the rule memory for

Returns:

  • (Array)

    The caluclated rule memory for the given object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/nanoc/base/compilation/rule_memory_calculator.rb', line 24

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 "Do not know how to calculate the rule memory for #{obj.inspect}"
    end

  result
end