Class: Alki::Reload::ReloadableDelegator

Inherits:
Delegator
  • Object
show all
Defined in:
lib/alki/reload/reloadable_delegator.rb

Instance Method Summary collapse

Constructor Details

#initialize(instance, ref) ⇒ ReloadableDelegator

Returns a new instance of ReloadableDelegator.



6
7
8
9
# File 'lib/alki/reload/reloadable_delegator.rb', line 6

def initialize(instance,ref)
  @instance = instance
  @ref = ref
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &blk) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/alki/reload/reloadable_delegator.rb', line 19

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

Instance Method Details

#__getobj__Object



11
12
13
14
15
16
17
# File 'lib/alki/reload/reloadable_delegator.rb', line 11

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