Class: Fig::ApplicationConfiguration

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

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplicationConfiguration

Returns a new instance of ApplicationConfiguration.



8
9
10
11
# File 'lib/fig/application_configuration.rb', line 8

def initialize()
  @data = []
  clear_cached_data
end

Instance Attribute Details

#base_whitelisted_urlObject

Returns the value of attribute base_whitelisted_url.



5
6
7
# File 'lib/fig/application_configuration.rb', line 5

def base_whitelisted_url
  @base_whitelisted_url
end

#remote_repository_urlObject

Returns the value of attribute remote_repository_url.



6
7
8
# File 'lib/fig/application_configuration.rb', line 6

def remote_repository_url
  @remote_repository_url
end

Instance Method Details

#[](key) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/fig/application_configuration.rb', line 27

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, call clear_cached, and lazy initialize as far as the list of things to exclude



42
43
44
# File 'lib/fig/application_configuration.rb', line 42

def clear_cached_data()
  @whitelist = nil
end

#ensure_url_whitelist_initializedObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fig/application_configuration.rb', line 13

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

#push_dataset(dataset) ⇒ Object



36
37
38
# File 'lib/fig/application_configuration.rb', line 36

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

#url_access_allowed?(url) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
# File 'lib/fig/application_configuration.rb', line 46

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