Sha256: 9bed0d37b45962de60ee6ca3094825964ee84c5cb7c31487f741c14994c7688d

Contents?: true

Size: 1.17 KB

Versions: 30

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

30 entries across 30 versions & 2 rubygems

Version Path
fig18-0.1.48 lib/fig/applicationconfiguration.rb
fig18-0.1.48-i386-mswin32 lib/fig/applicationconfiguration.rb
fig18-0.1.48-i386-mingw32 lib/fig/applicationconfiguration.rb
fig-0.1.48 lib/fig/applicationconfiguration.rb
fig-0.1.48-java lib/fig/applicationconfiguration.rb
fig18-0.1.47 lib/fig/applicationconfiguration.rb
fig18-0.1.47-i386-mswin32 lib/fig/applicationconfiguration.rb
fig18-0.1.47-i386-mingw32 lib/fig/applicationconfiguration.rb
fig-0.1.47 lib/fig/applicationconfiguration.rb
fig-0.1.47-java lib/fig/applicationconfiguration.rb
fig18-0.1.46 lib/fig/applicationconfiguration.rb
fig18-0.1.46-i386-mswin32 lib/fig/applicationconfiguration.rb
fig18-0.1.46-i386-mingw32 lib/fig/applicationconfiguration.rb
fig-0.1.46 lib/fig/applicationconfiguration.rb
fig-0.1.46-java lib/fig/applicationconfiguration.rb
fig-0.1.45-java lib/fig/applicationconfiguration.rb
fig-0.1.45 lib/fig/applicationconfiguration.rb
fig18-0.1.45 lib/fig/applicationconfiguration.rb
fig18-0.1.45-i386-mswin32 lib/fig/applicationconfiguration.rb
fig18-0.1.45-i386-mingw32 lib/fig/applicationconfiguration.rb