Class: PumaPlus::Options
- Inherits:
-
Object
- Object
- PumaPlus::Options
- Defined in:
- lib/puma_plus/config_file.rb
Overview
Three-layer option lookup: command line beats config file beats default.
Same precedence as puma's UserFileDefaultOptions, and for the same reason --
a config file is checked in and shared, a command line is what you type to
override it right now. Kept as three separate hashes rather than one merged
one so puma-plus --port 3000 still wins over a port 9292 in the file no
matter which was read first.
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(defaults = {}) ⇒ Options
constructor
A new instance of Options.
- #key?(key) ⇒ Boolean
-
#origin(key) ⇒ Object
Where a value came from.
- #to_h ⇒ Object
Constructor Details
#initialize(defaults = {}) ⇒ Options
Returns a new instance of Options.
14 15 16 17 18 |
# File 'lib/puma_plus/config_file.rb', line 14 def initialize(defaults = {}) @default = defaults @file = {} @user = {} end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
20 21 22 |
# File 'lib/puma_plus/config_file.rb', line 20 def default @default end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
20 21 22 |
# File 'lib/puma_plus/config_file.rb', line 20 def file @file end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
20 21 22 |
# File 'lib/puma_plus/config_file.rb', line 20 def user @user end |
Instance Method Details
#[](key) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/puma_plus/config_file.rb', line 22 def [](key) return @user[key] if @user.key?(key) return @file[key] if @file.key?(key) @default[key] end |
#key?(key) ⇒ Boolean
29 |
# File 'lib/puma_plus/config_file.rb', line 29 def key?(key) = @user.key?(key) || @file.key?(key) || @default.key?(key) |
#origin(key) ⇒ Object
Where a value came from. Used by --dry-run so a surprising setting can be
traced to the line that set it.
33 34 35 36 37 38 39 |
# File 'lib/puma_plus/config_file.rb', line 33 def origin(key) return :cli if @user.key?(key) return :config if @file.key?(key) return :default if @default.key?(key) nil end |
#to_h ⇒ Object
41 42 43 |
# File 'lib/puma_plus/config_file.rb', line 41 def to_h @default.merge(@file).merge(@user) end |