Class: BuildpackSupport::Cache::InternetAvailability

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/buildpack_support/cache/internet_availability.rb

Overview

Maintains the current state of internet availability.

Instance Method Summary collapse

Constructor Details

#initializeInternetAvailability

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

Parameters:

  • available (Boolean)

    whether the internet is available

  • message (String, nil) (defaults to: nil)

    an optional message to be printed when the availability is set



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, message = nil)
  @monitor.synchronize do
    if block_given?
      preserve_availability do
        @available = available
        @logger.warn { "Internet availability temporarily set to #{available}: #{message}" } if message

        yield
      end
    else
      @available = available
      @logger.warn { "Internet availability set to #{available}: #{message}" } if message
    end
  end
end

#available?Boolean

Returns whether the internet is available

Returns:

  • (Boolean)

    true if the internet is available, false otherwise



40
41
42
# File 'lib/buildpack_support/cache/internet_availability.rb', line 40

def available?
  @monitor.synchronize { @available }
end