Class: Comuna::Config
- Inherits:
-
Object
- Object
- Comuna::Config
- Defined in:
- lib/comuna/config.rb
Instance Attribute Summary collapse
-
#interfaces ⇒ Object
readonly
Returns the value of attribute interfaces.
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
-
#upstream ⇒ Object
readonly
Returns the value of attribute upstream.
Instance Method Summary collapse
- #extract_with_defaults!(config) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load! ⇒ Object
- #parsed ⇒ Object
- #raw ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
8 9 10 |
# File 'lib/comuna/config.rb', line 8 def initialize load! end |
Instance Attribute Details
#interfaces ⇒ Object (readonly)
Returns the value of attribute interfaces.
5 6 7 |
# File 'lib/comuna/config.rb', line 5 def interfaces @interfaces end |
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
5 6 7 |
# File 'lib/comuna/config.rb', line 5 def matches @matches end |
#upstream ⇒ Object (readonly)
Returns the value of attribute upstream.
5 6 7 |
# File 'lib/comuna/config.rb', line 5 def upstream @upstream end |
Instance Method Details
#extract_with_defaults!(config) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/comuna/config.rb', line 31 def extract_with_defaults!(config) port = config.fetch('port', 5300) @interfaces = config.fetch('interfaces', [[:udp, '0.0.0.0', port], [:tcp, '0.0.0.0', port]]) @upstream = config.fetch('upstream', [[:udp, '8.8.8.8', 53], [:tcp, '8.8.8.8', 53]]) @matches = config.fetch('matches', {myself: '0.0.0.0'}) end |
#load! ⇒ Object
12 13 14 |
# File 'lib/comuna/config.rb', line 12 def load! extract_with_defaults!(parsed) end |
#parsed ⇒ Object
26 27 28 29 |
# File 'lib/comuna/config.rb', line 26 def parsed read = YAML.load(raw) read.is_a?(Hash) ? read : {} end |
#raw ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/comuna/config.rb', line 16 def raw if File.exist?('config.yml') File.read('config.yml') elsif File.exist?('config.yaml') File.read('config.yaml') else '' end end |