Class: Nanoc::RuleDSL::Rule Private
- Inherits:
-
Object
- Object
- Nanoc::RuleDSL::Rule
- Defined in:
- lib/nanoc/rule_dsl/rule.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.
Contains the processing information for a item.
Instance Attribute Summary collapse
- #pattern ⇒ Object readonly private
-
#rep_name ⇒ Symbol
readonly
private
The name of the representation that will be compiled using this rule.
-
#snapshot_name ⇒ Symbol
readonly
private
The name of the snapshot this rule will apply to.
Instance Method Summary collapse
-
#applicable_to?(item) ⇒ Boolean
private
True if this rule can be applied to the given item rep, false otherwise.
-
#apply_to(rep, site:, executor:, view_context:) ⇒ void
private
Applies this rule to the given item rep.
-
#initialize(pattern, rep_name, block, snapshot_name: nil) ⇒ Rule
constructor
private
Creates a new item compilation rule with the given identifier regex, compiler and block.
Constructor Details
#initialize(pattern, rep_name, block, snapshot_name: nil) ⇒ 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.
Creates a new item compilation rule with the given identifier regex, compiler and block. The block will be called during compilation with the item rep as its argument.
32 33 34 35 36 37 |
# File 'lib/nanoc/rule_dsl/rule.rb', line 32 def initialize(pattern, rep_name, block, snapshot_name: nil) @pattern = pattern @rep_name = rep_name.to_sym @snapshot_name = snapshot_name @block = block end |
Instance Attribute Details
#pattern ⇒ Object (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.
16 17 18 |
# File 'lib/nanoc/rule_dsl/rule.rb', line 16 def pattern @pattern end |
#rep_name ⇒ Symbol (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 name of the representation that will be compiled using this rule.
8 9 10 |
# File 'lib/nanoc/rule_dsl/rule.rb', line 8 def rep_name @rep_name end |
#snapshot_name ⇒ Symbol (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 name of the snapshot this rule will apply to. Ignored for compilation rules, but used for routing rules.
14 15 16 |
# File 'lib/nanoc/rule_dsl/rule.rb', line 14 def snapshot_name @snapshot_name end |
Instance Method Details
#applicable_to?(item) ⇒ Boolean
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 true if this rule can be applied to the given item rep, false otherwise.
43 44 45 |
# File 'lib/nanoc/rule_dsl/rule.rb', line 43 def applicable_to?(item) @pattern.match?(item.identifier) end |
#apply_to(rep, site:, executor:, view_context:) ⇒ void
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.
Applies this rule to the given item rep.
55 56 57 58 59 60 |
# File 'lib/nanoc/rule_dsl/rule.rb', line 55 def apply_to(rep, site:, executor:, view_context:) context = Nanoc::RuleDSL::RuleContext.new( rep: rep, executor: executor, site: site, view_context: view_context, ) context.instance_exec(matches(rep.item.identifier), &@block) end |