Sha256: 4cb2349abdd181991dcc167ee7957c9ba56c480ba3c795797e6d5229bb1d95ee

Contents?: true

Size: 660 Bytes

Versions: 31

Compression:

Stored size: 660 Bytes

Contents

module Abstractivator
  module Trees

    class BlockCollector
      def initialize
        @config = {}
      end

      def when(path, &block)
        @config[path] = block
      end

      def get_path_tree
        path_tree = {}
        @config.each_pair do |path, block|
          set_hash_path(path_tree, path.split('/'), block)
        end
        path_tree
      end

      def delete
        @delete ||= Object.new
      end

      private

      def set_hash_path(h, names, block)
        orig = h
        while names.size > 1
          h = (h[names.shift] ||= {})
        end
        h[names.shift] = block
        orig
      end
    end

  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
abstractivator-0.20.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.19.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.18.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.17.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.16.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.15.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.14.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.13.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.12.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.11.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.10.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.8.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.7.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.6.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.5.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.4.1 lib/abstractivator/trees/block_collector.rb
abstractivator-0.4.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.3.1 lib/abstractivator/trees/block_collector.rb
abstractivator-0.3.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.2.0 lib/abstractivator/trees/block_collector.rb