Sha256: c3c43030a9206f4cb64e02be39668546799bdd0a2d23d2a28fd17b5da55b62c8

Contents?: true

Size: 1.01 KB

Versions: 17

Compression:

Stored size: 1.01 KB

Contents

module Middleman
  module CoreExtensions
    module Collections
      class LazyCollectorStep < BasicObject
        DELEGATE = [:hash, :eql?].freeze

        def initialize(name, args, block, parent=nil)
          @name = name
          @args = args
          @block = block

          @parent = parent
          @result = nil

          leaves << self
        end

        def leaves
          @parent.leaves
        end

        def value(ctx=nil)
          data = @parent.value(ctx)

          original_block = @block

          b = if ctx
            ::Proc.new do |*args|
              ctx.instance_exec(*args, &original_block)
            end
          else
            original_block
          end if original_block

          data.send(@name, *@args.deep_dup, &b)
        end

        def method_missing(name, *args, &block)
          return ::Kernel.send(name, *args, &block) if DELEGATE.include? name

          leaves.delete self

          LazyCollectorStep.new(name, args, block, self)
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
middleman-core-with-external-sources-watch-fix-4.1.10 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-with-external-sources-watch-fix-4.1.0 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.1.14 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.1.13 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.1.12 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.1.11 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.1.10 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.1.9 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.1.8 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.1.7 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.1.6 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.1.5 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.1.3 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.1.2 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.1.1 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.1.0 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.1.0.rc.2 lib/middleman-core/core_extensions/collections/lazy_step.rb