Sha256: 6a13dd66cfab3a6c3dec2d1df89c8c7a722762f43c1531e6a37c6897fbb8bc7a

Contents?: true

Size: 859 Bytes

Versions: 17

Compression:

Stored size: 859 Bytes

Contents

# frozen_string_literal: true

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

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

    contract Nanoc::Int::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::Int::ItemRep, C::KeywordArgs[
      site: Nanoc::Int::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

17 entries across 17 versions & 1 rubygems

Version Path
nanoc-4.11.0 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.10.4 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.10.3 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.10.2 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.10.1 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.10.0 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.9.9 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.9.8 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.9.7 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.9.6 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.9.5 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.9.4 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.9.3 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.9.2 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.9.1 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.9.0 lib/nanoc/rule_dsl/routing_rule.rb
nanoc-4.8.19 lib/nanoc/rule_dsl/routing_rule.rb