Class: BuildpackSupport::Cache::InternetAvailability
- Inherits:
-
Object
- Object
- BuildpackSupport::Cache::InternetAvailability
- Includes:
- Singleton
- Defined in:
- lib/buildpack_support/cache/internet_availability.rb
Overview
Maintains the current state of internet availability.
Instance Method Summary collapse
-
#available(available, message = nil) ⇒ Object
Sets whether the internet is available.
-
#available? ⇒ Boolean
Returns whether the internet is available.
-
#initialize ⇒ InternetAvailability
constructor
Creates a new instance.
Constructor Details
#initialize ⇒ InternetAvailability
Creates a new instance. Availability is assumed to be true
unless remote_downloads
is set to disabled
in config/cache.yml
.
31 32 33 34 35 |
# File 'lib/buildpack_support/cache/internet_availability.rb', line 31 def initialize @logger = BuildpackSupport::Logging::LoggerFactory.instance.get_logger InternetAvailability @monitor = Monitor.new @monitor.synchronize { @available = remote_downloads? } end |
Instance Method Details
#available(available, message = nil) ⇒ Object
Sets whether the internet is available
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/buildpack_support/cache/internet_availability.rb', line 49 def available(available, = nil) @monitor.synchronize do if block_given? preserve_availability do @available = available @logger.warn { "Internet availability temporarily set to #{available}: #{}" } if yield end else @available = available @logger.warn { "Internet availability set to #{available}: #{}" } if end end end |
#available? ⇒ Boolean
Returns whether the internet is available
40 41 42 |
# File 'lib/buildpack_support/cache/internet_availability.rb', line 40 def available? @monitor.synchronize { @available } end |