Class: Nightfury::Metric::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/nightfury/metric.rb

Direct Known Subclasses

TimeSeries, Value

Constant Summary collapse

ALLOWED_STEPS =
[:minute, :hour, :day, :week, :month]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Base



9
10
11
12
13
14
15
# File 'lib/nightfury/metric.rb', line 9

def initialize(name, options={})
  @name = name
  @redis = Nightfury.redis
  @redis_key_prefix = options[:redis_key_prefix]
  @store_as = options[:store_as]
  @step =  ALLOWED_STEPS.include?(options[:step]) ? options[:step] : :minute
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/nightfury/metric.rb', line 7

def name
  @name
end

#redisObject (readonly)

Returns the value of attribute redis.



7
8
9
# File 'lib/nightfury/metric.rb', line 7

def redis
  @redis
end

#redis_key_prefixObject (readonly)

Returns the value of attribute redis_key_prefix.



7
8
9
# File 'lib/nightfury/metric.rb', line 7

def redis_key_prefix
  @redis_key_prefix
end

#stepObject (readonly)

Returns the value of attribute step.



7
8
9
# File 'lib/nightfury/metric.rb', line 7

def step
  @step
end

#store_asObject (readonly)

Returns the value of attribute store_as.



7
8
9
# File 'lib/nightfury/metric.rb', line 7

def store_as
  @store_as
end

Instance Method Details

#deleteObject



23
24
25
# File 'lib/nightfury/metric.rb', line 23

def delete
  redis.del redis_key
end

#redis_keyObject



17
18
19
20
21
# File 'lib/nightfury/metric.rb', line 17

def redis_key
  prefix = redis_key_prefix.blank? ? '' : "#{redis_key_prefix}:"
  store_name = store_as ? store_as : name
  "#{prefix}#{store_name}" 
end