Class: Aqua::Stub

Inherits:
Object
  • Object
show all
Defined in:
lib/aqua/object/stub.rb

Direct Known Subclasses

FileStub

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Stub

TODO:

pass in information about parent, and path to the stub such that method missing replaces stub with actual object being stubbed and delegated to.

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

Parameters:

  • (Hash)
  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • :methods (Array)

    A hash of method names and values

  • :class (String)

    The class of the object being stubbed

  • :id (String)

    The id of the object being stubbed



17
18
19
20
21
22
23
24
# File 'lib/aqua/object/stub.rb', line 17

def initialize(opts)
  stub_methods( opts[:methods] || {} )
  
  self.delegate_class     = opts[:class]
  self.delegate_id        = opts[:id]
  self.parent_object      = opts[:parent]
  self.path_from_parent   = opts[:path] 
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (protected)



46
47
48
49
50
51
52
53
# File 'lib/aqua/object/stub.rb', line 46

def method_missing( method, *args, &block )
  load_delegate if delegate.nil?
  if delegate
    delegate.send( method, *args, &block )
  else
    missing_delegate_error
  end    
end

Instance Attribute Details

#delegateObject

Returns the value of attribute delegate.



3
4
5
# File 'lib/aqua/object/stub.rb', line 3

def delegate
  @delegate
end

#delegate_classObject

Returns the value of attribute delegate_class.



3
4
5
# File 'lib/aqua/object/stub.rb', line 3

def delegate_class
  @delegate_class
end

#delegate_idObject

Returns the value of attribute delegate_id.



3
4
5
# File 'lib/aqua/object/stub.rb', line 3

def delegate_id
  @delegate_id
end

#parent_objectObject

Returns the value of attribute parent_object.



3
4
5
# File 'lib/aqua/object/stub.rb', line 3

def parent_object
  @parent_object
end

#path_from_parentObject

Returns the value of attribute path_from_parent.



3
4
5
# File 'lib/aqua/object/stub.rb', line 3

def path_from_parent
  @path_from_parent
end

Class Method Details

.aqua_init(init, opts = Translator::Opts.new) ⇒ Object



26
27
28
# File 'lib/aqua/object/stub.rb', line 26

def self.aqua_init( init, opts=Translator::Opts.new )
  new( init )
end