Sha256: 94c3e4de9a5d59782261e9de1dbfa64200e6e07b0ca7dbcb2c11e89c889b4117

Contents?: true

Size: 1.05 KB

Versions: 20

Compression:

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

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

          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

20 entries across 20 versions & 2 rubygems

Version Path
middleman-core-4.5.1 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.5.0 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.4.3 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.4.2 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.4.0 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.3.11 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.3.10 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.3.8 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.3.7 lib/middleman-core/core_extensions/collections/lazy_step.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/middleman-core-4.3.3/lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.3.6 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.3.5 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.3.4 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.3.3 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.3.2 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.3.1 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.3.0 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.3.0.rc.1 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.2.1 lib/middleman-core/core_extensions/collections/lazy_step.rb
middleman-core-4.2.0 lib/middleman-core/core_extensions/collections/lazy_step.rb