Class: Puma::UserFileDefaultOptions
- Inherits:
-
Object
- Object
- Puma::UserFileDefaultOptions
- Defined in:
- lib/puma/configuration.rb
Overview
A class used for storing "leveled" configuration options.
In this class any "user" specified options take precedence over any "file" specified options, take precedence over any "default" options.
User input is preferred over "defaults":
= { foo: "bar" }
= { foo: "zoo" }
= UserFileDefaultOptions.new(, )
puts [:foo]
# => "bar"
All values can be accessed via all_of
puts .all_of(:foo)
# => ["bar", "zoo"]
A "file" option can be set. This config will be preferred over "default" options but will defer to any available "user" specified options.
= { foo: "bar" }
= { rackup: "zoo.rb" }
= UserFileDefaultOptions.new(, )
.[:rackup] = "sup.rb"
puts [:rackup]
# => "sup.rb"
The "default" options can be set via procs. These are resolved during runtime
via calls to finalize_values
Instance Attribute Summary collapse
-
#default_options ⇒ Object
readonly
Returns the value of attribute default_options.
-
#file_options ⇒ Object
readonly
Returns the value of attribute file_options.
-
#user_options ⇒ Object
readonly
Returns the value of attribute user_options.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #all_of(key) ⇒ Object
- #fetch(key, default_value = nil) ⇒ Object
- #final_options ⇒ Object
- #finalize_values ⇒ Object
-
#initialize(user_options, default_options) ⇒ UserFileDefaultOptions
constructor
A new instance of UserFileDefaultOptions.
Constructor Details
#initialize(user_options, default_options) ⇒ UserFileDefaultOptions
42 43 44 45 46 |
# File 'lib/puma/configuration.rb', line 42 def initialize(, ) = = {} = end |
Instance Attribute Details
#default_options ⇒ Object (readonly)
Returns the value of attribute default_options.
48 49 50 |
# File 'lib/puma/configuration.rb', line 48 def end |
#file_options ⇒ Object (readonly)
Returns the value of attribute file_options.
48 49 50 |
# File 'lib/puma/configuration.rb', line 48 def end |
#user_options ⇒ Object (readonly)
Returns the value of attribute user_options.
48 49 50 |
# File 'lib/puma/configuration.rb', line 48 def end |
Instance Method Details
#[](key) ⇒ Object
50 51 52 |
# File 'lib/puma/configuration.rb', line 50 def [](key) fetch(key) end |
#[]=(key, value) ⇒ Object
54 55 56 |
# File 'lib/puma/configuration.rb', line 54 def []=(key, value) [key] = value end |
#all_of(key) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/puma/configuration.rb', line 66 def all_of(key) user = [key] file = [key] default = [key] user = [user] unless user.is_a?(Array) file = [file] unless file.is_a?(Array) default = [default] unless default.is_a?(Array) user.compact! file.compact! default.compact! user + file + default end |
#fetch(key, default_value = nil) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/puma/configuration.rb', line 58 def fetch(key, default_value = nil) return [key] if .key?(key) return [key] if .key?(key) return [key] if .key?(key) default_value end |
#final_options ⇒ Object
90 91 92 93 94 |
# File 'lib/puma/configuration.rb', line 90 def .merge() .merge() end |
#finalize_values ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/puma/configuration.rb', line 82 def finalize_values .each do |k,v| if v.respond_to? :call [k] = v.call end end end |