Module: Arachni::Element::Capabilities::Refreshable

Included in:
Form, Link
Defined in:
lib/arachni/element/capabilities/refreshable.rb

Instance Method Summary collapse

Instance Method Details

#refresh(http_opts = {}, &block) ⇒ Form

Refreshes the form’s inputs and re-applies user updates.

The way it works is by requesting the Base#url, parsing the response and updating the form with the fresh form’s inputs.

Parameters:

  • http_opts (Hash) (defaults to: {})

    HTTP options to pass to the request

  • block (Block)

    if a block is given the request will be async and the block will be called with the updated form.

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/arachni/element/capabilities/refreshable.rb', line 33

def refresh( http_opts = {}, &block )
    updated = nil
    http.get( url.to_s, http_opts.merge( async: !!block ) ) do |res|
        # find ourselves
        f = self.class.from_response( res ).select { |f| f.id == id_from( :original ) }.first

        if !f
            block.call if block_given?
            next
        end

        # get user updates
        updates = changes
        # update the form's inputs with the fresh ones and re-apply the user changes
        updated = update( f.auditable ).update( updates )
        block.call( updated ) if block_given?
    end
    updated
end