Sha256: b28bfb39d065d2697b01a6d66b2c611c81a093ed783e6a14b94735344d6a9abd

Contents?: true

Size: 600 Bytes

Versions: 7

Compression:

Stored size: 600 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

      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

7 entries across 7 versions & 1 rubygems

Version Path
abstractivator-0.0.22 lib/abstractivator/trees/block_collector.rb
abstractivator-0.0.21 lib/abstractivator/trees/block_collector.rb
abstractivator-0.0.20 lib/abstractivator/trees/block_collector.rb
abstractivator-0.0.19 lib/abstractivator/trees/block_collector.rb
abstractivator-0.0.18 lib/abstractivator/trees/block_collector.rb
abstractivator-0.0.16 lib/abstractivator/trees/block_collector.rb
abstractivator-0.0.15 lib/abstractivator/trees/block_collector.rb