Class: Capybara::Experience::Pool
- Inherits:
-
Hash
- Object
- Hash
- Capybara::Experience::Pool
- Includes:
- Singleton
- Defined in:
- lib/capybara/experience/pool.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #idle ⇒ Object
- #reset_idle! ⇒ Object
- #take(driver: Capybara.current_driver, app_object_id: Capybara.app.object_id, key: nil) ⇒ Object
- #taken ⇒ Object
Instance Method Details
#[](key) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/capybara/experience/pool.rb', line 9 def [](key) super(key) || begin driver, _session_name, app_object_id = key.split(":") take(driver: driver.to_sym, app_object_id: app_object_id.to_i, key: key) end end |
#idle ⇒ Object
30 31 32 |
# File 'lib/capybara/experience/pool.rb', line 30 def idle @idle ||= [] end |
#reset_idle! ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/capybara/experience/pool.rb', line 38 def reset_idle! new_hash = each_with_object({}) do |(key, session), hash| hash[session_key(session)] = delete(key) end replace(new_hash) @idle = values nil end |
#take(driver: Capybara.current_driver, app_object_id: Capybara.app.object_id, key: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/capybara/experience/pool.rb', line 16 def take(driver: Capybara.current_driver, app_object_id: Capybara.app.object_id, key: nil) session = idle.find { |s| s.mode == driver && s.app.object_id == app_object_id } if session idle.delete(session) self[key] = delete(session_key(session)) if key else session = ::Capybara::Session.new(driver.to_sym, Capybara.app) key ||= session_key(session) self[key] = session end session end |
#taken ⇒ Object
34 35 36 |
# File 'lib/capybara/experience/pool.rb', line 34 def taken values - idle end |