class Userlist::Config

Constants

DEFAULT_CONFIGURATION

Attributes

config[R]
parent[R]

Public Class Methods

inherit(parent, config_from_arguments) click to toggle source
# 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
new(config_from_initialize = {}) click to toggle source
# File lib/userlist/config.rb, line 13
def initialize(config_from_initialize = {})
  @config = default_config
    .merge(config_from_initialize)
    .merge(config_from_environment)
end

Public Instance Methods

==(other) click to toggle source
# File lib/userlist/config.rb, line 38
def ==(other)
  config == other.config && parent == other.parent
end
merge(other_config) click to toggle source
# File lib/userlist/config.rb, line 26
def merge(other_config)
  self.class.inherit(self, other_config)
end
to_h() click to toggle source
# File lib/userlist/config.rb, line 34
def to_h
  parent ? parent.to_h.merge(config) : to_hash
end
to_hash() click to toggle source
# File lib/userlist/config.rb, line 30
def to_hash
  config
end
token_lifetime() click to toggle source
# File lib/userlist/config.rb, line 42
def token_lifetime
  self[:token_lifetime]&.to_i
end

Protected Instance Methods

[](key) click to toggle source
# File lib/userlist/config.rb, line 65
def [](key)
  config.key?(key) ? config[key] : parent && parent[key]
end
[]=(key, value) click to toggle source
# File lib/userlist/config.rb, line 69
def []=(key, value)
  config[key] = value
end
config_from_environment() click to toggle source
# File lib/userlist/config.rb, line 54
def config_from_environment
  default_config.keys.each_with_object({}) do |key, config|
    value = ENV["USERLIST_#{key.to_s.upcase}"]
    config[key] = value if value
  end
end
default_config() click to toggle source
# File lib/userlist/config.rb, line 50
def default_config
  DEFAULT_CONFIGURATION
end
key?(key) click to toggle source
# File lib/userlist/config.rb, line 61
def key?(key)
  config.key?(key) || parent&.key?(key)
end
method_missing(name, *args, &block) click to toggle source
Calls superclass method
# 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
respond_to_missing?(name, include_private = false) click to toggle source
Calls superclass method
# File lib/userlist/config.rb, line 73
def respond_to_missing?(name, include_private = false)
  name = name.to_s.sub(/=$/, '')
  key?(name.to_sym) || super
end