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.1.1 lib/abstractivator/trees/block_collector.rb
abstractivator-0.1.0 lib/abstractivator/trees/block_collector.rb
abstractivator-0.0.31 lib/abstractivator/trees/block_collector.rb
abstractivator-0.0.30 lib/abstractivator/trees/block_collector.rb
abstractivator-0.0.29 lib/abstractivator/trees/block_collector.rb
abstractivator-0.0.28 lib/abstractivator/trees/block_collector.rb
abstractivator-0.0.27 lib/abstractivator/trees/block_collector.rb
abstractivator-0.0.26 lib/abstractivator/trees/block_collector.rb
abstractivator-0.0.25 lib/abstractivator/trees/block_collector.rb
abstractivator-0.0.24 lib/abstractivator/trees/block_collector.rb
abstractivator-0.0.23 lib/abstractivator/trees/block_collector.rb