Sha256: d3be65db3109a5a465bbfd0e42c8e23699352be1bde811e5a0a2c42c39f9524d

Contents?: true

Size: 654 Bytes

Versions: 3

Compression:

Stored size: 654 Bytes

Contents

require 'delegate'

module Alki
  module Reload
    class ReloadableDelegator < Delegator
      def initialize(instance,ref)
        @instance = instance
        @ref = ref
      end

      def __getobj__
        if !@obj || @instance_version != @instance.__version__
          @obj = @ref.call
          @instance_version = @instance.__version__
        end
        @obj
      end

      def method_missing(method,*args,&blk)
        ref_meth = :"__reference_#{method}__"
        if respond_to?(ref_meth,true)
          ReloadableDelegator.new @instance, super(ref_meth, *args, &blk)
        else
          super
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
alki-reload-0.3.4 lib/alki/reload/reloadable_delegator.rb
alki-reload-0.3.3 lib/alki/reload/reloadable_delegator.rb
alki-reload-0.3.2 lib/alki/reload/reloadable_delegator.rb