Class: RiderServer::Config
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
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .configure(&block) ⇒ Object
-
.def_option(option_name, validator) ⇒ Object
Define a configuration option,
option_name
is a symbol representing the name of the configuration option, andvalidator
is a Validate object that will be used to validate the value of the option.
Instance Method Summary collapse
-
#initialize(config_file: "rider.rb") ⇒ Config
constructor
A new instance of Config.
-
#load_from(path) ⇒ Object
Load configuration from file
path
.
Constructor Details
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
60 61 62 |
# File 'lib/rider_server/config.rb', line 60 def @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 |