Class: Fig::ApplicationConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/fig/applicationconfiguration.rb

Overview

Configuration for the Fig program, as opposed to the configuration for a package.

Instance Method Summary collapse

Constructor Details

#initialize(remote_repository_url) ⇒ ApplicationConfiguration

Returns a new instance of ApplicationConfiguration.



5
6
7
8
9
# File 'lib/fig/applicationconfiguration.rb', line 5

def initialize(remote_repository_url)
  @data = []
  @remote_repository_url = remote_repository_url
  clear_cached_data
end

Instance Method Details

#[](key) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/fig/applicationconfiguration.rb', line 21

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

#clear_cached_dataObject

after push_dataset or unshift_dataset, call clear_cached, and lazy initialize as far as the list of things to exclude



40
41
42
# File 'lib/fig/applicationconfiguration.rb', line 40

def clear_cached_data()
  @whitelist = nil
end

#ensure_url_whitelist_initializedObject



11
12
13
14
15
16
17
18
19
# File 'lib/fig/applicationconfiguration.rb', line 11

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

#push_dataset(dataset) ⇒ Object



30
31
32
# File 'lib/fig/applicationconfiguration.rb', line 30

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

#unshift_dataset(dataset) ⇒ Object



34
35
36
# File 'lib/fig/applicationconfiguration.rb', line 34

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

#url_access_allowed?(url) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
# File 'lib/fig/applicationconfiguration.rb', line 44

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