Sha256: dba86f0d1e4c9f65a35e90e0bd76f0f5df22b646b553b3f86718bf059f09a88b

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

module Fig; end

# Configuration for the Fig program, as opposed to the configuration in a
# package.
class Fig::ApplicationConfiguration
  def initialize(remote_repository_url)
    @data = []
    @remote_repository_url = remote_repository_url
    clear_cached_data
  end

  def ensure_url_whitelist_initialized()
    return if not @whitelist.nil?
    whitelist = self['url whitelist']
    if whitelist.nil?
      @whitelist = []
    else
      @whitelist = [@remote_repository_url, whitelist].flatten
    end
  end

  def [](key)
    @data.each do |dataset|
      if dataset.has_key?(key)
        return dataset[key]
      end
    end
    return nil
  end

  def push_dataset(dataset)
    @data.push(dataset)
  end

  def unshift_dataset(dataset)
    @data.unshift(dataset)
  end

  # after push_dataset or unshift_dataset, call clear_cached, and lazy
  # initialize as far as the list of things to exclude
  def clear_cached_data()
    @whitelist = nil
  end

  def url_access_allowed?(url)
    ensure_url_whitelist_initialized
    return true if @whitelist.empty?
    @whitelist.each do |allowed_url|
      return true if url.match(/\A#{Regexp.quote(allowed_url)}\b/)
    end
    return false
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fig-0.1.62 lib/fig/applicationconfiguration.rb
fig-0.1.61 lib/fig/applicationconfiguration.rb
fig-0.1.59 lib/fig/applicationconfiguration.rb