Module: Qtrix::Namespacing
- Included in:
- Qtrix, Matrix, Matrix::QueuePicker, Matrix::Reader, Matrix::RowBuilder, Override, Queue
- Defined in:
- lib/qtrix/namespacing.rb
Overview
Provides support for namespacing the various redis keys so we can have multiple configuration sets and a pointer to the current namespace or configuration set.
This will allow for us to set up different configurations for different scenarios and to switch between them easily.
Scenarios might be things like:
-
day vs night configuration
-
weekday vs weekend configuration
-
common flood handling distributions.
Most interaction should be through the mixin and not the manager singelton here. Example:
class Foo
include Qtrix::Namespacing
@redis_namespace = :foo # or [:current, :foo]
def some_method
redis.keys # constrained to :qtrix:foo:*
end
end
Defined Under Namespace
Classes: Manager
Class Method Summary collapse
Instance Method Summary collapse
-
#extract_args(arg_count, *args) ⇒ Object
Extracts the namespace, if any, from the arg list.
-
#redis(*namespaces) ⇒ Object
Returns a redis client namespaced to the #redis_namespace defined in the object/class, or to the id within the parent option.
-
#redis_namespace ⇒ Object
Returns the redis namespace as defined in the instance or class.
Class Method Details
.included(base) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/qtrix/namespacing.rb', line 30 def self.included(base) # make redis_key and current_namespaced available to both class and # instance methods base.instance_exec do extend Namespacing end end |
Instance Method Details
#extract_args(arg_count, *args) ⇒ Object
Extracts the namespace, if any, from the arg list.
60 61 62 63 64 65 66 |
# File 'lib/qtrix/namespacing.rb', line 60 def extract_args(arg_count, *args) if arg_count == args.size [:current] + args else args end end |
#redis(*namespaces) ⇒ Object
Returns a redis client namespaced to the #redis_namespace defined in the object/class, or to the id within the parent option. An id of :current will be evaluated to the current namespace. By default, this a root (qtrix:) namespaced client. Examples:
43 44 45 46 |
# File 'lib/qtrix/namespacing.rb', line 43 def redis(*namespaces) all_namespaces = redis_namespace + namespaces Manager.instance.redis(*all_namespaces) end |
#redis_namespace ⇒ Object
Returns the redis namespace as defined in the instance or class
51 52 53 54 55 56 |
# File 'lib/qtrix/namespacing.rb', line 51 def redis_namespace namespaces = Array( self.instance_variable_get(:@redis_namespace) || self.class.instance_variable_get(:@redis_namespace) ) end |