Class: Userlist::Config
- Inherits:
-
Object
show all
- Defined in:
- lib/userlist/config.rb
Constant Summary
collapse
- DEFAULT_CONFIGURATION =
{
push_key: nil,
push_id: nil,
push_endpoint: 'https://push.userlist.com/',
push_strategy: :threaded,
push_strategy_options: {},
log_level: :warn,
token_lifetime: 3600
}.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config_from_initialize = {}) ⇒ Config
Returns a new instance of Config.
13
14
15
16
17
|
# File 'lib/userlist/config.rb', line 13
def initialize(config_from_initialize = {})
@config = default_config
.merge(config_from_initialize)
.merge(config_from_environment)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/userlist/config.rb', line 78
def method_missing(name, *args, &block)
if respond_to_missing?(name)
name = name.to_s
method = name =~ /=$/ ? :[]= : :[]
name = name.sub(/=$/, '').to_sym
send(method, name, *args, &block)
else
super
end
end
|
Class Method Details
.inherit(parent, config_from_arguments) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/userlist/config.rb', line 19
def self.inherit(parent, config_from_arguments)
config = allocate
config.instance_variable_set(:@parent, parent)
config.instance_variable_set(:@config, config_from_arguments.to_hash)
config
end
|
Instance Method Details
#==(other) ⇒ Object
38
39
40
|
# File 'lib/userlist/config.rb', line 38
def ==(other)
config == other.config && parent == other.parent
end
|
#merge(other_config) ⇒ Object
26
27
28
|
# File 'lib/userlist/config.rb', line 26
def merge(other_config)
self.class.inherit(self, other_config)
end
|
#to_h ⇒ Object
34
35
36
|
# File 'lib/userlist/config.rb', line 34
def to_h
parent ? parent.to_h.merge(config) : to_hash
end
|
#to_hash ⇒ Object
30
31
32
|
# File 'lib/userlist/config.rb', line 30
def to_hash
config
end
|
#token_lifetime ⇒ Object
42
43
44
|
# File 'lib/userlist/config.rb', line 42
def token_lifetime
self[:token_lifetime]&.to_i
end
|