Class: Flunky::Session
- Inherits:
-
Object
- Object
- Flunky::Session
- Defined in:
- lib/flunky/session.rb
Overview
Owns one driver for the life of a browsing session, caches the latest snapshot, and hands out the action DSL. This is the object callers hold.
Instance Attribute Summary collapse
-
#driver ⇒ Object
readonly
Returns the value of attribute driver.
Instance Method Summary collapse
- #actions ⇒ Object
- #close ⇒ Object
-
#initialize(driver: nil, **opts) ⇒ Session
constructor
Per-session options override the global configuration.
-
#observe ⇒ Object
Re-read the page and cache the fresh snapshot.
-
#snapshot ⇒ Object
Memoized view; captures once on first use so refs exist before any action.
- #visit(url) ⇒ Object
Constructor Details
#initialize(driver: nil, **opts) ⇒ Session
Per-session options override the global configuration. A custom backend can be injected with driver:; otherwise we build a Ferrum driver.
11 12 13 14 15 16 |
# File 'lib/flunky/session.rb', line 11 def initialize(driver: nil, **opts) @options = Flunky.configuration.to_h.merge(opts) @driver = driver || build_default_driver @driver.start @snapshot = nil end |
Instance Attribute Details
#driver ⇒ Object (readonly)
Returns the value of attribute driver.
7 8 9 |
# File 'lib/flunky/session.rb', line 7 def driver @driver end |
Instance Method Details
#actions ⇒ Object
34 35 36 |
# File 'lib/flunky/session.rb', line 34 def actions @actions ||= Actions.new(@driver, self) end |
#close ⇒ Object
38 39 40 |
# File 'lib/flunky/session.rb', line 38 def close @driver.quit end |
#observe ⇒ Object
Re-read the page and cache the fresh snapshot.
25 26 27 |
# File 'lib/flunky/session.rb', line 25 def observe @snapshot = Snapshot.capture(@driver, max_elements: @options[:max_elements]) end |
#snapshot ⇒ Object
Memoized view; captures once on first use so refs exist before any action.
30 31 32 |
# File 'lib/flunky/session.rb', line 30 def snapshot @snapshot ||= observe end |
#visit(url) ⇒ Object
18 19 20 21 22 |
# File 'lib/flunky/session.rb', line 18 def visit(url) @driver.go_to(url) @snapshot = nil self end |