Class: DevDNSd::Configuration

Inherits:
Bovem::Configuration
  • Object
show all
Defined in:
lib/devdnsd/configuration.rb

Overview

This class holds the configuration of the application.

Instance Method Summary (collapse)

Constructor Details

- (Configuration) initialize(file = nil, overrides = {}, logger = nil)

Creates a new configuration. A configuration file is a plain Ruby file with a top-level config object.

Example:

ruby config.add_rule("match.dev", "10.0.0.1")

Parameters:

  • file (String) (defaults to: nil)

    The file to read.

  • overrides (Hash) (defaults to: {})

    A set of values which override those set in the configuration file.

  • logger (Logger) (defaults to: nil)

    The logger to use for notifications.



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/devdnsd/configuration.rb', line 64

def initialize(file = nil, overrides = {}, logger = nil)
  super(file, overrides, logger)

  # Make sure some arguments are of correct type
  self.log_file = $stdout if log_file == "STDOUT"
  self.log_file = $stderr if log_file == "STDERR"
  self.port = port.to_integer
  self.log_level = log_level.to_integer

  # Add a default rule
  add_rule(/.+/, "127.0.0.1") if rules.blank?
end

Instance Method Details

- (Array) add_rule(*args, &block)

Adds a rule to the configuration.

Parameters:

  • args (Array)

    The rule’s arguments.

  • block (Proc)

    An optional block for the rule.

Returns:

  • (Array)

    The current set of rule.

See Also:



83
84
85
# File 'lib/devdnsd/configuration.rb', line 83

def add_rule(*args, &block)
  rules << DevDNSd::Rule.create(*args, &block)
end