Sha256: dda6b3895f990af1bc19abf022128a4c09bf7426c3d23ba58863aaff6a97a9ed

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

module Representable
  class Pipeline < Array # i hate that.
    module Function
      class Insert
        def call(arr, func, options)
          arr = arr.dup
          delete!(arr, func) if options[:delete]
          replace!(arr, options[:replace], func) if options[:replace]
          arr
        end

      private
        def replace!(arr, old_func, new_func)
          arr.each_with_index { |func, index|
            if func.is_a?(Collect)
              arr[index] = Collect[*Pipeline::Insert.(func, new_func, replace: old_func)]
            end

            arr[index] = new_func if func==old_func
          }
        end

        def delete!(arr, removed_func)
          arr.delete(removed_func)

          # TODO: make nice.
          arr.each_with_index { |func, index|
            if func.is_a?(Collect)
              arr[index] = Collect[*Pipeline::Insert.(func, removed_func, delete: true)]
            end
          }
        end
      end
    end

    Insert = Pipeline::Function::Insert.new
  end # Pipeline
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/representable-3.2.0/lib/representable/insert.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/representable-3.2.0/lib/representable/insert.rb
representable-3.2.0 lib/representable/insert.rb
representable-3.1.1 lib/representable/insert.rb
representable-3.1.0 lib/representable/insert.rb