Class: Arachni::Page::DOM::Transition
- Defined in:
- lib/arachni/page/dom/transition.rb
Overview
Defined Under Namespace
Classes: Error
Constant Summary collapse
- NON_PLAYABLE =
Non-playable events.
Set.new([:request])
- ZERO_DEPTH =
Events without a DOM depth.
Set.new([:request])
Instance Attribute Summary collapse
-
#element ⇒ Browser::ElementLocator
readonly
HTML element which received the #event.
-
#event ⇒ Symbol
Event triggered on #element.
-
#options ⇒ Hash
readonly
Extra options.
- #time ⇒ Float
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#complete ⇒ Transition
Marks the transition as finished.
-
#completed? ⇒ Bool
`true` if the transition has completed, `false` otherwise.
-
#depth ⇒ Integer
Depth for this transition.
- #dup ⇒ Object
- #hash ⇒ Object
-
#initialize(*args, &block) ⇒ Transition
constructor
A new instance of Transition.
-
#play(browser) ⇒ Transition?
New transition as a result of the play, `nil` if the play wasn't successful.
-
#playable? ⇒ Bool
`true` if the transition is for an event that can be played, `false` otherwise.
-
#running? ⇒ Bool
`true` if the transition is in progress, `false` otherwise.
-
#start(element, event, options = {}, &block) ⇒ Transition
`self`.
- #to_hash ⇒ Hash (also: #to_h)
-
#to_rpc_data ⇒ Hash
Data representing this instance that are suitable the RPC transmission.
- #to_s ⇒ String
Constructor Details
#initialize(*args, &block) ⇒ Transition
If arguments are provided they will be passed to #start.
Returns a new instance of Transition.
102 103 104 105 106 107 |
# File 'lib/arachni/page/dom/transition.rb', line 102 def initialize( *args, &block ) @options = {} return if !args.any? start( *args, &block ) end |
Instance Attribute Details
#element ⇒ Browser::ElementLocator (readonly)
Returns HTML element which received the #event.
78 79 80 |
# File 'lib/arachni/page/dom/transition.rb', line 78 def element @element end |
#event ⇒ Symbol
Returns Event triggered on #element.
82 83 84 |
# File 'lib/arachni/page/dom/transition.rb', line 82 def event @event end |
#options ⇒ Hash (readonly)
Returns Extra options.
86 87 88 |
# File 'lib/arachni/page/dom/transition.rb', line 86 def @options end |
Class Method Details
.from_rpc_data(data) ⇒ Transition
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/arachni/page/dom/transition.rb', line 266 def self.from_rpc_data( data ) instance = allocate data.each do |name, value| value = case name when 'event' value.to_sym when 'element' if value.is_a? String data['event'].to_s == 'request' ? value : value.to_sym else Browser::ElementLocator.from_rpc_data( value ) end when 'options' value.my_symbolize_keys(false) else value end instance.instance_variable_set( "@#{name}", value ) end instance end |
Instance Method Details
#==(other) ⇒ Object
297 298 299 |
# File 'lib/arachni/page/dom/transition.rb', line 297 def ==( other ) hash == other.hash end |
#complete ⇒ Transition
Will stop the timer for #time.
Marks the transition as finished.
166 167 168 169 170 171 172 173 174 |
# File 'lib/arachni/page/dom/transition.rb', line 166 def complete fail Error::Completed, 'Transition has completed.' if completed? fail Error::NotRunning, 'Transition is not running.' if !running? @time = Time.now - @clock @clock = nil self end |
#completed? ⇒ Bool
Returns `true` if the transition has completed, `false` otherwise.
222 223 224 |
# File 'lib/arachni/page/dom/transition.rb', line 222 def completed? !!@time end |
#depth ⇒ Integer
Returns Depth for this transition.
180 181 182 |
# File 'lib/arachni/page/dom/transition.rb', line 180 def depth ZERO_DEPTH.include?( event ) ? 0 : 1 end |
#dup ⇒ Object
240 241 242 |
# File 'lib/arachni/page/dom/transition.rb', line 240 def dup rpc_clone end |
#hash ⇒ Object
293 294 295 |
# File 'lib/arachni/page/dom/transition.rb', line 293 def hash to_hash.tap { |h| h.delete :time }.hash end |
#play(browser) ⇒ Transition?
Returns New transition as a result of the play, `nil` if the play wasn't successful.
193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/arachni/page/dom/transition.rb', line 193 def play( browser ) fail Error::NotPlayable, "Transition is not playable: #{self}" if !playable? if element == :page && event == :load return browser.goto( [:url], cookies: [:cookies], take_snapshot: false ) end browser.fire_event element, event, end |
#playable? ⇒ Bool
Returns `true` if the transition is for an event that can be played, `false` otherwise.
231 232 233 |
# File 'lib/arachni/page/dom/transition.rb', line 231 def playable? !NON_PLAYABLE.include?( event ) end |
#running? ⇒ Bool
Returns `true` if the transition is in progress, `false` otherwise.
212 213 214 |
# File 'lib/arachni/page/dom/transition.rb', line 212 def running? !!@clock end |
#start(element, event, options = {}, &block) ⇒ Transition
Will start the timer for #time.
Returns `self`.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/arachni/page/dom/transition.rb', line 135 def start( element, event, = {}, &block ) fail Error::Completed, 'Transition has completed.' if completed? fail Error::Running, 'Transition is already running' if running? if ![Symbol, String, Browser::ElementLocator].include?( element.class ) fail Error::InvalidElement end self.event = event @element = element @options = .my_symbolize_keys(false) @clock = Time.now return self if !block_given? block.call complete end |
#to_hash ⇒ Hash Also known as: to_h
245 246 247 248 249 250 251 252 253 |
# File 'lib/arachni/page/dom/transition.rb', line 245 def to_hash { element: element.is_a?( Browser::ElementLocator ) ? element.to_h : element, event: event, options: , time: time } end |
#to_rpc_data ⇒ Hash
Returns Data representing this instance that are suitable the RPC transmission.
258 259 260 261 262 |
# File 'lib/arachni/page/dom/transition.rb', line 258 def to_rpc_data h = to_hash.my_stringify_keys(false) h['element'] = element.to_rpc_data_or_self h end |
#to_s ⇒ String
236 237 238 |
# File 'lib/arachni/page/dom/transition.rb', line 236 def to_s "[#{time.to_f}s] '#{event}' on: #{element}" end |