Module: Arachni::Mixins::Observable
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 )
* observer_instance.on_<hookname>( &block )
Instance Method Summary collapse
Methods included from Utilities
#cookie_encode, #cookies_from_document, #cookies_from_file, #cookies_from_response, #exception_jail, #exclude_path?, #extract_domain, #form_decode, #form_encode, #form_parse_request_body, #forms_from_document, #forms_from_response, #get_path, #hash_keys_to_str, #html_decode, #html_encode, #include_path?, #links_from_document, #links_from_response, #normalize_url, #page_from_response, #page_from_url, #parse_query, #parse_set_cookie, #parse_url_vars, #path_in_domain?, #path_too_deep?, #remove_constants, #seed, #skip_path?, #to_absolute, #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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/arachni/mixins/observable.rb', line 41 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', 'on' add_block( hook, &block ) return when 'call' call_blocks( hook, args ) return end end fail NoMethodError.new( "Undefined method '#{sym.to_s}'.", sym, args ) end |