Class: ParameterTransformers::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/parameter_transformers.rb

Instance Method Summary collapse

Constructor Details

#initialize(target, transformers = {}) ⇒ Proxy

Returns a new instance of Proxy.



11
12
13
# File 'lib/parameter_transformers.rb', line 11

def initialize(target, transformers={})
  @target, @transformers = target, transformers
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/parameter_transformers.rb', line 19

def method_missing(m, *args, &block)
  params = @target.method(m).parameters.map(&:last)
  t_args = args.dup
  params.each_with_index do |param, ix|
    if @transformers[[m, param]] &&
      @transformers[[m, param]].kind_of?(Proc)
        t_args[ix] =
          @transformers[[m, param]].call(t_args[ix])
    end
  end
  @target.send(m, *t_args, &block)
end

Instance Method Details

#respond_to?(symbol, include_priv = false) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/parameter_transformers.rb', line 15

def respond_to?(symbol, include_priv=false)
  @target.respond_to?(symbol, include_priv)
end