Class: WifiWand::Platforms::Mac::SystemProfilerWifiDataProvider
- Inherits:
-
Object
- Object
- WifiWand::Platforms::Mac::SystemProfilerWifiDataProvider
- Defined in:
- lib/wifi_wand/platforms/mac/system_profiler_wifi_data_provider.rb
Constant Summary collapse
- CACHE_CONTEXTS_KEY =
:wifi_wand_system_profiler_wifi_data_cache_contexts- SYSTEM_PROFILER_WIFI_ARGS =
%w[system_profiler -json SPAirPortDataType].freeze
- SYSTEM_PROFILER_TIMEOUT_SECONDS =
15
Instance Method Summary collapse
- #active_cache_context ⇒ Object
- #data(timeout_in_secs: nil) ⇒ Object
-
#initialize(owner:, command_runner:) ⇒ SystemProfilerWifiDataProvider
constructor
A new instance of SystemProfilerWifiDataProvider.
- #invalidate_cache ⇒ Object
- #with_cache_scope ⇒ Object
Constructor Details
#initialize(owner:, command_runner:) ⇒ SystemProfilerWifiDataProvider
Returns a new instance of SystemProfilerWifiDataProvider.
15 16 17 18 19 20 |
# File 'lib/wifi_wand/platforms/mac/system_profiler_wifi_data_provider.rb', line 15 def initialize(owner:, command_runner:) @owner = owner @command_runner = command_runner @cache_mutex = Mutex.new @cache_generation = 0 end |
Instance Method Details
#active_cache_context ⇒ Object
52 53 54 |
# File 'lib/wifi_wand/platforms/mac/system_profiler_wifi_data_provider.rb', line 52 def active_cache_context current_cache_contexts&.fetch(@owner, nil) end |
#data(timeout_in_secs: nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/wifi_wand/platforms/mac/system_profiler_wifi_data_provider.rb', line 29 def data(timeout_in_secs: nil) context = active_cache_context generation = cache_generation return context[:data] if cached_data_current?(context, generation) parsed_data = parse_system_profiler_wifi_data(timeout_in_secs: timeout_in_secs) cache_data(context, generation, parsed_data) parsed_data end |
#invalidate_cache ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/wifi_wand/platforms/mac/system_profiler_wifi_data_provider.rb', line 40 def invalidate_cache @cache_mutex.synchronize do @cache_generation += 1 end context = active_cache_context return unless context context.delete(:data) context.delete(:generation) end |
#with_cache_scope ⇒ Object
22 23 24 25 26 27 |
# File 'lib/wifi_wand/platforms/mac/system_profiler_wifi_data_provider.rb', line 22 def with_cache_scope context = enter_cache_scope yield ensure exit_cache_scope(context) if context end |