Class: IptablesWeb::Configuration

Inherits:
Hash
  • Object
show all
Defined in:
lib/iptables_web/configuration.rb

Constant Summary collapse

CONFIG_FILES =
%W(#{ENV['HOME']}/.iptables-web/config.yml /etc/iptables-web/config.yml)
STATIC_RULES_FILES =
%W(#{ENV['HOME']}/.iptables-web/static_rules /etc/iptables-web/static_rules)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



8
9
10
11
12
13
14
15
# File 'lib/iptables_web/configuration.rb', line 8

def initialize
  CONFIG_FILES.each do |config|
    if load(config)
      @loaded = true
      break
    end
  end
end

Instance Attribute Details

#loadedObject

Returns the value of attribute loaded.



4
5
6
# File 'lib/iptables_web/configuration.rb', line 4

def loaded
  @loaded
end

Class Method Details

.config_dirObject



28
29
30
# File 'lib/iptables_web/configuration.rb', line 28

def self.config_dir
  File.join(ENV['HOME'], '.iptables-web')
end

.static_rulesObject



22
23
24
25
26
# File 'lib/iptables_web/configuration.rb', line 22

def self.static_rules
  STATIC_RULES_FILES.map do |file|
    File.exist?(file) ? File.read(file) : nil
  end.compact.join("\n").strip
end

Instance Method Details

#load(config) ⇒ Object



17
18
19
20
# File 'lib/iptables_web/configuration.rb', line 17

def load(config)
  clear
  merge! YAML.load File.read(config) if File.exist?(config)
end