Class: Puma::UserFileDefaultOptions
Relationships & Source Files | |
Inherits: | Object |
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
Class Method Summary
Instance Attribute Summary
- #default_options readonly
- #file_options readonly
- #user_options readonly
Instance Method Summary
Constructor Details
.new(user_options, default_options) ⇒ UserFileDefaultOptions
# File 'lib/puma/configuration.rb', line 49
def initialize(, ) @user_options = @file_options = {} @default_options = end
Instance Attribute Details
#default_options (readonly)
[ GitHub ]# File 'lib/puma/configuration.rb', line 55
attr_reader :, :, :
#file_options (readonly)
[ GitHub ]# File 'lib/puma/configuration.rb', line 55
attr_reader :, :, :
#user_options (readonly)
[ GitHub ]# File 'lib/puma/configuration.rb', line 55
attr_reader :, :, :
Instance Method Details
#[](key)
[ GitHub ]# File 'lib/puma/configuration.rb', line 57
def [](key) fetch(key) end
#[]=(key, value)
[ GitHub ]# File 'lib/puma/configuration.rb', line 61
def []=(key, value) [key] = value end
#all_of(key)
[ GitHub ]# File 'lib/puma/configuration.rb', line 73
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)
[ GitHub ]# File 'lib/puma/configuration.rb', line 65
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
[ GitHub ]# File 'lib/puma/configuration.rb', line 97
def .merge( ) .merge( ) end
#finalize_values
[ GitHub ]# File 'lib/puma/configuration.rb', line 89
def finalize_values @default_options.each do |k,v| if v.respond_to? :call @default_options[k] = v.call end end end