Sha256: 452e1ea10ea875685826a06eb70814a7b95f9fd9d177e47f707f82289571b1da

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

require 'valise/stack'

module Valise
  class Stack
    class ExtensionsDecorator < Stack
      def initialize(stack)
        @stack = stack
        @extensions = []
        @stacks = Hash.new do |h,segments|
          h[segments] = @stack.valise.get(segments)
        end
      end

      attr_accessor :extensions

      def inspect
        @stack.inspect + "x#{extensions.inspect}"
      end

      def valise
        @stack.valise
      end

      def reget(root)
        decorated = self.new(super)
        decorated.extensions = self.extensions
        decorated
      end

      def merged(item)
        item.stack.merged(item)
      end

      def diffed(item, value)
        item.stack.diffed(item, value)
      end

      def rel_path
        @stack.rel_path
      end

      def each
        return enum_for(:each) unless block_given?
        @stack.each do |item|
          @extensions.each do |ext|
            dir, file = *item.segments.split
            ext_stack = @stacks[dir + (file.to_s + ext)]
            yield(ext_stack.item_for(item.root))
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
valise-1.0.0 lib/valise/stack/extensions-decorator.rb