Method: Copland::ServiceModel::Proxy#method_missing

Defined in:
lib/copland/models/proxy.rb

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

Attempts to invoke the given message on the service. If the service has not yet been instantiated, it will be instantiated and stored.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/copland/models/proxy.rb', line 52

def method_missing( sym, *args, &block )
  unless @instance || @instantiation_failed
    @mutex.synchronize do
      unless @instance || @instantiation_failed
        begin
          @instance = @service_point.instantiate( &@init )
        rescue Exception
          @instantiation_failed = true
          raise
        end
      end
    end
  end

  unless @instantiation_failed
    @instance.__send__ sym, *args, &block
  else
    # just return nil... this way, a failed instantiation won't barf
    # more than once... I hope...
  end
end