Sha256: b48796bd24c54ca53b8916a4ce089e73b64b87a5d6103027f7c9a198bad303e3

Contents?: true

Size: 863 Bytes

Versions: 7

Compression:

Stored size: 863 Bytes

Contents

# frozen_string_literal: true

module Nanoc::RuleDSL
  class RoutingRule < Rule
    include Nanoc::Core::ContractsSupport

    contract C::None => C::Maybe[Symbol]
    attr_reader :snapshot_name

    contract Nanoc::Core::Pattern, Symbol, Proc, C::KeywordArgs[snapshot_name: C::Optional[Symbol]] => C::Any
    def initialize(pattern, rep_name, block, snapshot_name: nil)
      super(pattern, rep_name, block)

      @snapshot_name = snapshot_name
    end

    contract Nanoc::Core::ItemRep, C::KeywordArgs[
      site: Nanoc::Core::Site,
      view_context: Nanoc::ViewContextForPreCompilation,
    ] => C::Any
    def apply_to(rep, site:, view_context:)
      context = Nanoc::RuleDSL::RoutingRuleContext.new(
        rep: rep, site: site, view_context: view_context,
      )

      context.instance_exec(matches(rep.item.identifier), &@block)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
nanoc-4.11.11 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.11.10 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.11.9 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.11.8 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.11.7 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.11.6 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.11.5 lib/nanoc/rule_dsl/routing_rule.rb