Sha256: 262439a1fbd5a3713d563573ed08475a190dcc55278e9f72fbf1a2360886e5a3

Contents?: true

Size: 1.17 KB

Versions: 10

Compression:

Stored size: 1.17 KB

Contents

module Fig
  class 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
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
fig18-0.1.50-i386-mswin32 lib/fig/applicationconfiguration.rb
fig18-0.1.50 lib/fig/applicationconfiguration.rb
fig-0.1.50-java lib/fig/applicationconfiguration.rb
fig-0.1.50 lib/fig/applicationconfiguration.rb
fig18-0.1.50-i386-mingw32 lib/fig/applicationconfiguration.rb
fig-0.1.49-java lib/fig/applicationconfiguration.rb
fig-0.1.49 lib/fig/applicationconfiguration.rb
fig18-0.1.49 lib/fig/applicationconfiguration.rb
fig18-0.1.49-i386-mswin32 lib/fig/applicationconfiguration.rb
fig18-0.1.49-i386-mingw32 lib/fig/applicationconfiguration.rb