Class: Nanoc::Int::RuleMemory

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/nanoc/base/entities/rule_memory.rb

Instance Method Summary collapse

Constructor Details

#initialize(item_rep, actions: []) ⇒ RuleMemory

Returns a new instance of RuleMemory



6
7
8
9
# File 'lib/nanoc/base/entities/rule_memory.rb', line 6

def initialize(item_rep, actions: [])
  @item_rep = item_rep
  @actions = actions
end

Instance Method Details

#[](idx) ⇒ Object



17
18
19
# File 'lib/nanoc/base/entities/rule_memory.rb', line 17

def [](idx)
  @actions[idx]
end

#add_filter(filter_name, params) ⇒ Object



22
23
24
25
# File 'lib/nanoc/base/entities/rule_memory.rb', line 22

def add_filter(filter_name, params)
  @actions << Nanoc::Int::ProcessingActions::Filter.new(filter_name, params)
  self
end

#add_layout(layout_identifier, params) ⇒ Object



28
29
30
31
# File 'lib/nanoc/base/entities/rule_memory.rb', line 28

def add_layout(layout_identifier, params)
  @actions << Nanoc::Int::ProcessingActions::Layout.new(layout_identifier, params)
  self
end

#add_snapshot(snapshot_name, path) ⇒ Object



34
35
36
37
38
# File 'lib/nanoc/base/entities/rule_memory.rb', line 34

def add_snapshot(snapshot_name, path)
  will_add_snapshot(snapshot_name)
  @actions << Nanoc::Int::ProcessingActions::Snapshot.new(snapshot_name, path)
  self
end

#any_layouts?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/nanoc/base/entities/rule_memory.rb', line 46

def any_layouts?
  @actions.any? { |a| a.is_a?(Nanoc::Int::ProcessingActions::Layout) }
end

#eachObject



63
64
65
66
# File 'lib/nanoc/base/entities/rule_memory.rb', line 63

def each
  @actions.each { |a| yield(a) }
  self
end

#mapObject



69
70
71
72
73
74
# File 'lib/nanoc/base/entities/rule_memory.rb', line 69

def map
  self.class.new(
    @item_rep,
    actions: @actions.map { |a| yield(a) },
  )
end

#pathsObject



51
52
53
54
55
# File 'lib/nanoc/base/entities/rule_memory.rb', line 51

def paths
  snapshot_actions.each_with_object({}) do |action, paths|
    paths[action.snapshot_name] = action.path
  end
end

#serializeObject

TODO: Add contract



58
59
60
# File 'lib/nanoc/base/entities/rule_memory.rb', line 58

def serialize
  to_a.map(&:serialize)
end

#sizeObject



12
13
14
# File 'lib/nanoc/base/entities/rule_memory.rb', line 12

def size
  @actions.size
end

#snapshot_actionsObject



41
42
43
# File 'lib/nanoc/base/entities/rule_memory.rb', line 41

def snapshot_actions
  @actions.select { |a| a.is_a?(Nanoc::Int::ProcessingActions::Snapshot) }
end