Class: WifiWand::ConnectionManager
- Inherits:
-
Object
- Object
- WifiWand::ConnectionManager
- Includes:
- StringPredicates
- Defined in:
- lib/wifi_wand/services/connection_manager.rb
Constant Summary collapse
- MAX_NETWORK_NAME_BYTES =
32- MAX_PASSWORD_LENGTH =
Exactly 64 hexadecimal characters is treated as a raw PSK.
64- MAX_PASSPHRASE_LENGTH =
Non-raw passphrases must fit within 63 UTF-8 bytes.
63- RAW_PSK_PATTERN =
/\A\h{64}\z/- CONTROL_CHAR_PATTERN =
/\p{Cntrl}/
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#connect(network_name, password = nil, skip_saved_password_lookup: false) ⇒ Object
Connects to the passed network name, optionally with password.
-
#initialize(model, verbose: false, runtime_config: nil) ⇒ ConnectionManager
constructor
A new instance of ConnectionManager.
-
#last_connection_used_saved_password? ⇒ Boolean
Returns true if the last completed connection used a saved password.
- #verbose? ⇒ Boolean
Methods included from StringPredicates
string_nil_or_blank?, string_nil_or_empty?
Constructor Details
#initialize(model, verbose: false, runtime_config: nil) ⇒ ConnectionManager
Returns a new instance of ConnectionManager.
22 23 24 25 26 |
# File 'lib/wifi_wand/services/connection_manager.rb', line 22 def initialize(model, verbose: false, runtime_config: nil) @model = model @runtime_config = runtime_config || RuntimeConfig.new(verbose: verbose) @last_connection_used_saved_password = nil end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
19 20 21 |
# File 'lib/wifi_wand/services/connection_manager.rb', line 19 def model @model end |
Instance Method Details
#connect(network_name, password = nil, skip_saved_password_lookup: false) ⇒ Object
Connects to the passed network name, optionally with password. Turns WiFi on first, in case it was turned off. Relies on model implementation of _connect().
IMPORTANT: This method returns once the SSID association is confirmed, NOT when DNS or Internet connectivity are available. The OS may still be negotiating an IP address or DNS at that point. To guarantee full connectivity after connecting, follow with: model.till(:internet_on) or CLI: till internet_on [timeout_secs]
Note: The @last_connection_used_saved_password flag is cleared at the start of each connect attempt and only set after connection verification succeeds. Failed or no-op connection attempts leave the flag false.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/wifi_wand/services/connection_manager.rb', line 42 def connect(network_name, password = nil, skip_saved_password_lookup: false) reset_connection_state network_name, password = normalize_inputs(network_name, password) validate_network_name(network_name) # If we're already connected to the desired network, no need to proceed return if already_connected?(network_name) password, used_saved_password = resolve_password(network_name, password, skip_saved_password_lookup: skip_saved_password_lookup) perform_connection(network_name, password) verify_connection(network_name, password) store_saved_password_usage(used_saved_password) nil end |
#last_connection_used_saved_password? ⇒ Boolean
Returns true if the last completed connection used a saved password. Failed or no-op connect() calls return false.
63 |
# File 'lib/wifi_wand/services/connection_manager.rb', line 63 def last_connection_used_saved_password? = !!@last_connection_used_saved_password |
#verbose? ⇒ Boolean
28 |
# File 'lib/wifi_wand/services/connection_manager.rb', line 28 def verbose? = runtime_config.verbose |