Module: SpecToolsExtensions

Overview

Utility Module for SpecTools

The module defines some useful extensions that SpecTools utilizes.

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

:nodoc:



39
40
41
42
43
44
45
# File 'lib/spectools.rb', line 39

def method_missing(method, *args) #:nodoc:
	if SpecTools::Config.default_access_method != nil
		call_extension(method,*args)
	else
		super.method_missing
	end
end

Class Method Details

.method_missing(method, *args) ⇒ Object

:nodoc:



47
48
49
50
51
52
53
# File 'lib/spectools.rb', line 47

def self.method_missing(method, *args) #:nodoc:
	if SpecTools::Config.default_access_method != nil
		call_extension(method,*args)
	else
		super.method_missing
	end
end

Instance Method Details

#call_default_extension(method, *args) ⇒ Object

This method is explicitly called by the standard SpecTools object methods.

Calls call_extension with the method sent.

If SpecTools::Config.default_access_method is not set, SpecTools::NoAccessMethodError is raised.



61
62
63
64
65
66
67
# File 'lib/spectools.rb', line 61

def call_default_extension(method,*args)
	if SpecTools::Config.default_access_method != nil
		call_extension(method,*args)
	else
		raise SpecTools::NoAccessMethodError, 'In order to use this method, you must define Config::default_access_method'
	end
end

#call_extension(method, *args) ⇒ Object

This method allows extension developers to extend SpecTools without having to redefine stock methods. call_extension is usually invoked through method_missing or call_default_extension. It takes a method (in symbol form) and appends the prefix defined in SpecTools::Config.default_access_method . Example:

call_extension(:get_attr,*args)

if SpecTools::Config.default_access_method is set to :access, call_extension will attempt call access_call_extension(*args) on itself, if the method is available. If the method does not exist, NoMethodError is raised.



30
31
32
33
34
35
36
37
# File 'lib/spectools.rb', line 30

def call_extension(method,*args)
	newmethod = SpecTools::Config.default_access_method.to_s + '_' + method.to_s
	if self.respond_to?(newmethod.to_sym)
		self.send(newmethod.to_sym, *args)
	else
		raise NoMethodError, "undefined method `#{newmethod}' for #{self}"
	end
end