Class: RiderServer::Config

Inherits:
Object show all
Defined in:
lib/rider_server/config.rb

Constant Summary collapse

DEFAULTS =
{
  host: "localhost",
  port: 7888,

  # Whether to capture RIDER exceptions and send them to the
  # client.
  capture_exceptions: false,

  # The number of exceptions to keep in the history.
  exception_history_size: 10,

  # The log level
  log_level: :INFO
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file: "rider.rb") ⇒ Config

Returns a new instance of Config.



62
63
64
65
66
67
68
# File 'lib/rider_server/config.rb', line 62

def initialize(config_file: "rider.rb")
  @options = DEFAULTS.dup

  if File.file?(config_file)
    config.load_from(config_file)
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



60
61
62
# File 'lib/rider_server/config.rb', line 60

def options
  @options
end

Class Method Details

.configure(&block) ⇒ Object



29
30
31
32
33
# File 'lib/rider_server/config.rb', line 29

def self.configure(&block)
  instance = new
  instance.instance_eval(&block)
  instance
end

.def_option(option_name, validator) ⇒ Object

Define a configuration option, option_name is a symbol representing the name of the configuration option, and validator is a Validate object that will be used to validate the value of the option.



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rider_server/config.rb', line 39

def self.def_option(option_name, validator)
  define_method :"#{option_name}" do |value = nil|
    if value
      @options[option_name] = validator.validate(value)
    else
      unless @options.key?(option_name)
        raise ArgumentError, "Option #{option_name} not set"
      end

      @options[option_name]
    end
  end
end

Instance Method Details

#load_from(path) ⇒ Object

Load configuration from file path. The contents of the file will be evaluated within the context of this class instance.



72
73
74
# File 'lib/rider_server/config.rb', line 72

def load_from(path)
  instance_eval(File.read(path), path, 1)
end