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

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

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

Example:

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
76
# 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 = resolve_log_file

  self.pid_file = File.absolute_path(File.expand_path(pid_file))
  self.port = port.to_integer
  self.log_level = log_level.to_integer

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

Instance Method Details

#add_rule(match: /.+/, reply: "127.0.0.1", type: :A, options: {}, &block) ⇒ Array

Adds a rule to the configuration.

Parameters:

  • match (String|Regexp) (defaults to: /.+/)

    The pattern to match.

  • reply (String|Symbol) (defaults to: "127.0.0.1")

    The IP or hostname to reply back to the client. It can be omitted (and it will be ignored) if a block is provided.

  • type (Symbol) (defaults to: :A)

    The type of request to match.

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

    A list of options for the request.

  • block (Proc)

    An optional block to compute the reply instead of using the reply parameter.

Returns:

  • (Array)

    The current set of rule.



86
87
88
# File 'lib/devdnsd/configuration.rb', line 86

def add_rule(match: /.+/, reply: "127.0.0.1", type: :A, options: {}, &block)
  rules << DevDNSd::Rule.create(match: match, reply: reply, type: type, options: options, &block)
end