Class: RedisCounters::Bucket
- Inherits:
-
Object
- Object
- RedisCounters::Bucket
- Defined in:
- lib/redis_counters/bucket.rb
Instance Attribute Summary collapse
-
#bucket_params ⇒ Object
readonly
Returns the value of attribute bucket_params.
-
#counter ⇒ Object
readonly
Returns the value of attribute counter.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(counter, bucket_params) ⇒ Bucket
constructor
A new instance of Bucket.
-
#params(options = {}) ⇒ Object
Protected: Возвращает букет в виде массива параметров, однозначно его идентифицирующих.
Constructor Details
#initialize(counter, bucket_params) ⇒ Bucket
Returns a new instance of Bucket.
10 11 12 13 14 15 16 17 |
# File 'lib/redis_counters/bucket.rb', line 10 def initialize(counter, bucket_params) @counter = counter @bucket_params = bucket_params.with_indifferent_access if bucket_keys.present? && bucket_params.blank? && required? raise ArgumentError, "You must specify a #{self.class.name}" end end |
Instance Attribute Details
#bucket_params ⇒ Object (readonly)
Returns the value of attribute bucket_params.
20 21 22 |
# File 'lib/redis_counters/bucket.rb', line 20 def bucket_params @bucket_params end |
#counter ⇒ Object (readonly)
Returns the value of attribute counter.
19 20 21 |
# File 'lib/redis_counters/bucket.rb', line 19 def counter @counter end |
Class Method Details
.default_options ⇒ Object
6 7 8 |
# File 'lib/redis_counters/bucket.rb', line 6 def self. {:only_leaf => false} end |
Instance Method Details
#params(options = {}) ⇒ Object
Protected: Возвращает букет в виде массива параметров, однозначно его идентифицирующих.
cluster - Hash - хеш параметров, определяющий букет. options - Hash - хеш опций:
:only_leaf - Boolean -
Метод генерирует исключение ArgumentError, если переданы параметры не верно идентифицирующие букет. Например: ключи группировки счетчика :param2, :param3, а переданы :param3. Метод генерирует исключение ArgumentError, ‘You must specify a cluster’, если букет передан в виде пустого хеша, но группировка используется в счетчике.
Returns Array.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/redis_counters/bucket.rb', line 37 def params( = {}) .reverse_merge!(self.class.) bucket_keys.inject(Array.new) do |result, key| param = ([:only_leaf] ? bucket_params.fetch(key) : bucket_params[key]) next result unless bucket_params.has_key?(key) next result << param if result.size >= bucket_keys.index(key) raise ArgumentError, 'An incorrectly specified %s %s' % [self.class.name, bucket_params] end end |