Class: Aqua::Stub

  • Delegator
    • Aqua::Stub

Attributes

Instance Attributes

delegate_class [RW] public

Sets the attribute delegate_class.

delegate_id [RW] public

Sets the attribute delegate_id.

Constructor Summary

public initialize(opts)

Builds a new stub object which returns cached/stubbed methods until such a time as a non-cached method is requested.

Meta Tags

Parameters:

Options Hash opts
Key Name Default Value Accepted Types Description
:methods N/A [Array]

A hash of method names and values

:class N/A [String]

The class of the object being stubbed

:id N/A [String]

The id of the object being stubbed

[View source]


28
29
30
31
32
33
34
35
# File 'lib/aqua/object/stub.rb', line 28

def initialize( opts )
  meths = opts[:methods] || {}
  temp_stub = TempStub.new( meths )
  super( temp_stub )
  @_sd_obj = temp_stub
  self.delegate_class = opts[:class]
  self.delegate_id = opts[:id]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

public method_missing(method, *args)
[View source]


40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/aqua/object/stub.rb', line 40

def method_missing( method, *args )
  if __getobj__.class.to_s != delegate_class.to_s
    load_delegate
    # resend! 
    if (args.size == 1 && !args.first.nil?) 
      __getobj__.send( method.to_sym, eval(args.map{|value| "'#{value}'"}.join(', ')) )
    else
      __getobj__.send( method.to_sym )
    end    
  else
    raise NoMethodError
  end
end

Public Visibility

Public Instance Method Summary

#__getobj__
#__setobj__(obj)
#load_delegate

Public Instance Method Details

__getobj__

public __getobj__
[View source]


54
55
56
# File 'lib/aqua/object/stub.rb', line 54

def __getobj__
  @_sd_obj          # return object we are delegating to, required
end

__setobj__

public __setobj__(obj)
[View source]


58
59
60
# File 'lib/aqua/object/stub.rb', line 58

def __setobj__(obj)
  @_sd_obj = obj    # change delegation object, a feature we're providing
end

load_delegate

public load_delegate
[View source]


62
63
64
# File 'lib/aqua/object/stub.rb', line 62

def load_delegate
  __setobj__( delegate_class.constantize.load( delegate_id ) )
end
Generated on Thursday, August 27 2009 at 05:50:24 PM by YARD 0.2.3.5 (ruby-1.8.6).