Class: OnyxCord::Configuration
- Inherits:
-
Object
- Object
- OnyxCord::Configuration
- Defined in:
- lib/onyxcord/core/configuration.rb
Overview
Runtime defaults for OnyxCord bots.
Defined Under Namespace
Classes: CacheSizes
Constant Summary collapse
- MODES =
%i[raw hybrid object].freeze
- EXECUTORS =
%i[pool inline].freeze
- CACHE_PRESETS =
{ none: { users: false, voice_regions: false, servers: false, channels: false, pm_channels: false, thread_members: false, server_previews: false, members: false, messages: false }, minimal: { users: false, voice_regions: false, servers: true, channels: true, pm_channels: false, thread_members: false, server_previews: false, members: false, messages: false }, full: { users: true, voice_regions: true, servers: true, channels: true, pm_channels: true, thread_members: true, server_previews: true, members: true, messages: true } }.freeze
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#cache_sizes ⇒ Object
Returns the value of attribute cache_sizes.
-
#event_executor ⇒ Object
Returns the value of attribute event_executor.
-
#event_queue_size ⇒ Object
Returns the value of attribute event_queue_size.
-
#event_workers ⇒ Object
Returns the value of attribute event_workers.
-
#mode ⇒ Object
Returns the value of attribute mode.
Class Method Summary collapse
Instance Method Summary collapse
- #dup ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #normalize_cache(value = @cache) ⇒ Object
- #normalize_event_executor(value = @event_executor) ⇒ Object
- #normalize_event_queue_size(value = @event_queue_size) ⇒ Object
- #normalize_event_workers(value = @event_workers) ⇒ Object
- #normalize_mode(value = @mode) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
89 90 91 92 93 94 95 96 |
# File 'lib/onyxcord/core/configuration.rb', line 89 def initialize @mode = :hybrid @cache = :none @cache_sizes = CacheSizes.new @event_executor = :pool @event_workers = 4 @event_queue_size = nil end |
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
87 88 89 |
# File 'lib/onyxcord/core/configuration.rb', line 87 def cache @cache end |
#cache_sizes ⇒ Object
Returns the value of attribute cache_sizes.
87 88 89 |
# File 'lib/onyxcord/core/configuration.rb', line 87 def cache_sizes @cache_sizes end |
#event_executor ⇒ Object
Returns the value of attribute event_executor.
87 88 89 |
# File 'lib/onyxcord/core/configuration.rb', line 87 def event_executor @event_executor end |
#event_queue_size ⇒ Object
Returns the value of attribute event_queue_size.
87 88 89 |
# File 'lib/onyxcord/core/configuration.rb', line 87 def event_queue_size @event_queue_size end |
#event_workers ⇒ Object
Returns the value of attribute event_workers.
87 88 89 |
# File 'lib/onyxcord/core/configuration.rb', line 87 def event_workers @event_workers end |
#mode ⇒ Object
Returns the value of attribute mode.
87 88 89 |
# File 'lib/onyxcord/core/configuration.rb', line 87 def mode @mode end |
Class Method Details
.configure {|current| ... } ⇒ Object
158 159 160 |
# File 'lib/onyxcord/core/configuration.rb', line 158 def configure yield current end |
.current ⇒ Object
154 155 156 |
# File 'lib/onyxcord/core/configuration.rb', line 154 def current @current ||= new end |
.reset! ⇒ Object
162 163 164 |
# File 'lib/onyxcord/core/configuration.rb', line 162 def reset! @current = new end |
Instance Method Details
#dup ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/onyxcord/core/configuration.rb', line 98 def dup copy = self.class.new copy.mode = @mode copy.cache = @cache.is_a?(Hash) ? @cache.dup : @cache copy.cache_sizes = @cache_sizes.dup copy.event_executor = @event_executor copy.event_workers = @event_workers copy.event_queue_size = @event_queue_size copy end |
#normalize_cache(value = @cache) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/onyxcord/core/configuration.rb', line 139 def normalize_cache(value = @cache) cache = value.nil? ? @cache : value case cache when Hash CACHE_PRESETS[:none].merge(cache.transform_keys(&:to_sym)) else preset = cache.to_sym raise ArgumentError, "Unknown cache preset: #{cache.inspect}" unless CACHE_PRESETS[preset] CACHE_PRESETS[preset].dup end end |
#normalize_event_executor(value = @event_executor) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/onyxcord/core/configuration.rb', line 116 def normalize_event_executor(value = @event_executor) executor = (value || @event_executor).to_sym return executor if EXECUTORS.include?(executor) raise ArgumentError, "Unknown event executor: #{value.inspect}" end |
#normalize_event_queue_size(value = @event_queue_size) ⇒ Object
130 131 132 133 134 135 136 137 |
# File 'lib/onyxcord/core/configuration.rb', line 130 def normalize_event_queue_size(value = @event_queue_size) return nil if value.nil? size = Integer(value) raise ArgumentError, 'event_queue_size must be greater than zero' unless size.positive? size end |
#normalize_event_workers(value = @event_workers) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/onyxcord/core/configuration.rb', line 123 def normalize_event_workers(value = @event_workers) workers = Integer(value || @event_workers) raise ArgumentError, 'event_workers must be greater than zero' unless workers.positive? workers end |
#normalize_mode(value = @mode) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/onyxcord/core/configuration.rb', line 109 def normalize_mode(value = @mode) mode = (value || @mode).to_sym return mode if MODES.include?(mode) raise ArgumentError, "Unknown OnyxCord mode: #{value.inspect}" end |