Sha256: c2dd437bf503f093516dd55f8bf07bd5b3135c04e78c2f8ea662b07bfea7297e
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
# frozen_string_literal: true module Totoro class Initializer DEFAULT_CONFIG = %i[default connect queue].freeze def excute config = Rails.application.config_for(:totoro).with_indifferent_access # set default queue class Totoro.const_set('Queue', default_queue_class(config)) # set custom queue class (config.symbolize_keys.keys - DEFAULT_CONFIG).each do |prefix| prefix_module(prefix, queue_class(prefix)) end end private def default_queue_class(config) if config.key?(:default) queue_class(:default) else Class.new(Totoro::BaseQueue) end end def queue_class(prefix) custom_queue_class = Class.new(Totoro::BaseQueue) custom_queue_class.define_singleton_method('config') do @config ||= Totoro::Config.new(prefix) end custom_queue_class end def prefix_module(prefix, custom_queue_class) prefix_module = Totoro.const_set(prefix.camelize, Module.new) prefix_module.const_set('Queue', custom_queue_class) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
totoro-0.1.4 | lib/totoro/initializer.rb |