Sha256: 81e62c2b70f0190eee1e2b1b8e701835362d0cf0a33c90a1a21c277b4f8c176e

Contents?: true

Size: 839 Bytes

Versions: 5

Compression:

Stored size: 839 Bytes

Contents

module Putter
  class Follower < BasicObject
    include MethodCreator

    attr_reader :object, :proxy

    def initialize(obj, options={})
      @object = obj
      @proxy = MethodProxy.new
      begin
        @object.singleton_class.send(:prepend, proxy)
      rescue ::NoMethodError
        ::Kernel.raise ::Putter::BasicObjectError
      end
      @data = FollowerData.new(@object, @proxy, options)
    end

    def method_missing(method, *args, &blk)
      if @data.add_method?(method)
        add_method(method)
      end

      if blk
        @object.send(method, *args, &blk)
      else
        @object.send(method, *args)
      end
    end

    def add_method(method)
      proxy_method_data = ProxyMethodData.new(label: @data.label, method: method)

      add_putter_method_to_proxy(@proxy, proxy_method_data)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
putter-0.7.0 lib/putter/follower.rb
putter-0.6.1 lib/putter/follower.rb
putter-0.6.0 lib/putter/follower.rb
putter-0.5.1 lib/putter/follower.rb
putter-0.5.0 lib/putter/follower.rb