Sha256: aaad5d0a5d33c3184bf21790c20512e6be8a350b9c91dbb0919b9e2e2f4e5db0

Contents?: true

Size: 1.47 KB

Versions: 4

Compression:

Stored size: 1.47 KB

Contents

module Contextify
  class PendingContext

    include Enumerable

    # The path being loaded
    attr_reader :path

    # The blocks to be loaded
    attr_accessor :blocks

    #
    # Creates a new PendingContext object.
    #
    # @param [String] path
    #   The path the pending context was loaded from.
    #
    def initialize(path)
      @path = File.expand_path(path)
      @blocks = {}
    end

    #
    # Iterates over each context name in the pending context.
    #
    # @yield [name]
    #   The block will be passed each name of the pending context blocks.
    #
    # @yieldparam [String] name
    #   The name of a pending context block.
    #
    def each_class(&block)
      @blocks.each_key do |name|
        block.call(Contextify.contexts[name])
      end
    end

    #
    # Iterates over each block in the pending context.
    #
    # @yield [block]
    #   The block will be passed each pending context block.
    #
    # @yieldparam [Proc] block
    #   A pending context block.
    #
    def each_block(&block)
      @blocks.each_value(&block)
    end

    #
    # Iterates over each context name and block in the pending context.
    #
    # @yield [name, block]
    #   The block will be passed each pending context block and it's
    #   context name.
    #
    # @yieldparam [String] name
    #   The context name of the block.
    #
    # @yieldparam [Proc] block
    #   A pending context block.
    #
    def each(&block)
      @blocks.each(&block)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
contextify-0.2.0 lib/contextify/pending_context.rb
contextify-0.1.6 lib/contextify/pending_context.rb
contextify-0.1.5 lib/contextify/pending_context.rb
contextify-0.1.4 lib/contextify/pending_context.rb