Module: Arachni::Mixins::Observable

Includes:
Arachni::Module::Utilities
Included in:
Framework, HTTP
Defined in:
lib/arachni/mixins/observable.rb

Overview

Provides a flexible way to make any Class observable via callbacks/hooks using simple dynamic programming with the help of “method_missing()”.

The observable classes (those which include this module) use:

* call_<hookname>( *args )

to call specific hooks.

The observers set hooks using:

* observer_instance.add_<hookname>( &block )

@author: Tasos “Zapotek” Laskos

<[email protected]>
<[email protected]>

@version: 0.1

Instance Method Summary collapse

Methods included from Arachni::Module::Utilities

#exception_jail, #get_path, #hash_keys_to_str, #normalize_url, #read_file, #seed, #uri_decode, #uri_encode, #uri_parse, #uri_parser, #url_sanitize

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Raises:

  • (NoMethodError)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/arachni/mixins/observable.rb', line 38

def method_missing( sym, *args, &block )

    # grab the action (add/call) and the hook name
    action, hook = sym.to_s.split( '_', 2 )

    @__hooks       ||= {}
    @__hooks[hook] ||= []

    if( action && hook )
        case action

        when 'add'
            add_block( hook, &block )
            return

         when 'call'
            call_blocks( hook, args )
            return
        end
    end

    raise NoMethodError.new( "Undefined method '#{sym.to_s}'.", sym, args )
end