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
#available_port, #cookie_encode, #cookies_from_document, #cookies_from_file, #cookies_from_response, #exception_jail, #exclude_path?, #extract_domain, #follow_protocol?, #form_decode, #form_encode, #form_parse_request_body, #forms_from_document, #forms_from_response, #generate_token, #get_path, #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?, #port_available?, #rand_port, #redundant_path?, #remove_constants, #seed, #skip_page?, #skip_path?, #skip_resource?, #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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/arachni/mixins/observable.rb', line 48 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 |
Instance Method Details
#clear_observers ⇒ Object
44 45 46 |
# File 'lib/arachni/mixins/observable.rb', line 44 def clear_observers @__hooks.clear if @__hooks end |