Sha256: 596d0108932517f5af2c787e33c6f1fd78af45ba13df1af8ef36f43b107a0725

Contents?: true

Size: 1010 Bytes

Versions: 3

Compression:

Stored size: 1010 Bytes

Contents

module Transproc
  # Transformation functions for Procs
  #
  # @example
  #   require 'ostruct'
  #   require 'transproc/proc'
  #
  #   include Transproc::Helper
  #
  #   fn = t(
  #     :map_value,
  #     'foo_bar',
  #     t(:bind, OpenStruct.new(prefix: 'foo'), -> s { [prefix, s].join('_') })
  #   )
  #
  #   fn["foo_bar" => "bar"]
  #   # => {"foo_bar" => "foo_bar"}
  #
  # @api public
  module ProcTransformations
    extend Registry

    # Change the binding for the given function
    #
    # @example
    #   Transproc(
    #     :bind,
    #     OpenStruct.new(prefix: 'foo'),
    #     -> s { [prefix, s].join('_') }
    #   )['bar']
    #   # => "foo_bar"
    #
    # @param [Proc]
    #
    # @return [Proc]
    #
    # @api public
    def self.bind(value, binding, fn)
      binding.instance_exec(value, &fn)
    end

    # @deprecated Register methods globally
    (methods - Registry.instance_methods - Registry.methods)
      .each { |name| Transproc.register name, t(name) }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
transproc-0.4.2 lib/transproc/proc.rb
transproc-0.4.1 lib/transproc/proc.rb
transproc-0.4.0 lib/transproc/proc.rb