Sha256: 2caf2eef7986d0082e9e12c11c745856eae160335d205309701d5ff5bdcb95e4

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

module Nanoc::Int
  # @api private
  class DependencyTracker
    class Null
      include Nanoc::Int::ContractsSupport

      contract C::Or[Nanoc::Int::Item, Nanoc::Int::Layout] => C::Any
      def enter(_obj)
      end

      contract C::None => C::Any
      def exit
      end

      contract C::Or[Nanoc::Int::Item, Nanoc::Int::Layout] => C::Any
      def bounce(_obj)
      end
    end

    include Nanoc::Int::ContractsSupport

    def initialize(dependency_store)
      @dependency_store = dependency_store
      @stack = []
    end

    contract C::Or[Nanoc::Int::Item, Nanoc::Int::Layout] => C::Any
    def enter(obj)
      unless @stack.empty?
        Nanoc::Int::NotificationCenter.post(:dependency_created, @stack.last, obj)
        @dependency_store.record_dependency(@stack.last, obj)
      end

      @stack.push(obj)
    end

    contract C::None => C::Any
    def exit
      @stack.pop
    end

    contract C::Or[Nanoc::Int::Item, Nanoc::Int::Layout] => C::Any
    def bounce(obj)
      enter(obj)
      exit
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nanoc-4.4.0 lib/nanoc/base/services/dependency_tracker.rb