Sha256: 6e1c8d6ef313a54d3051bf3d527e656ad8f05cf356a5c5011dd5c7ea3182400d

Contents?: true

Size: 954 Bytes

Versions: 11

Compression:

Stored size: 954 Bytes

Contents

module Peaty
  
  class Proxy
    attr_accessor :target, :connection, :options
    
    def initialize(target, connection, options = {})
      @target, @connection, @options = target, connection, options.with_indifferent_access
    end
    
    def method_missing(method, *args)
      return @target.method(method).unbind.bind(self).call(*args) if @target.class.respond_to?(method)
      options = args.extract_options!
      args << @options.merge(options)
      @target.with_connection(@connection).send(method, *args)
    end
    
    def filter(*args)
      options = args.extract_options!
      options.each do |(key, value)|
        @options[key] = Array.wrap(@options.delete(:key)).concat(Array.wrap(value))
      end
      
      @options[:rest] = Array.wrap(@options.delete(:rest)).concat(args)
      
      self
    end
    
    def self.build(attrs = {})
      @target.build(@options.merge(attrs.with_indifferent_access))
    end
  end
  
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
peaty-0.6.0.beta1 lib/peaty/proxy.rb
peaty-0.5.0 lib/peaty/proxy.rb
peaty-0.4.8 lib/peaty/proxy.rb
peaty-0.4.7 lib/peaty/proxy.rb
peaty-0.4.6 lib/peaty/proxy.rb
peaty-0.4.5 lib/peaty/proxy.rb
peaty-0.4.4 lib/peaty/proxy.rb
peaty-0.4.3 lib/peaty/proxy.rb
peaty-0.4.2 lib/peaty/proxy.rb
peaty-0.4.1 lib/peaty/proxy.rb
peaty-0.4.0 lib/peaty/proxy.rb