Class: Nightfury::Identity::Base
- Inherits:
-
Object
- Object
- Nightfury::Identity::Base
- Defined in:
- lib/nightfury/identity.rb
Constant Summary collapse
- METRIC_MAPPINGS =
{ :value => Nightfury::Metric::Value, :time_series => Nightfury::Metric::TimeSeries, :avg_time_series => Nightfury::Metric::AvgTimeSeries, :count_time_series => Nightfury::Metric::CountTimeSeries }
Class Attribute Summary collapse
-
.metrics ⇒ Object
readonly
Returns the value of attribute metrics.
-
.store_as ⇒ Object
Returns the value of attribute store_as.
-
.tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
-
#tags ⇒ Object
Returns the value of attribute tags.
Class Method Summary collapse
- .metric(name, type = :value, options = {}) ⇒ Object
- .name ⇒ Object
- .tag(name, options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(id, options = {}) ⇒ Base
constructor
A new instance of Base.
- #key_prefix ⇒ Object
- #new_record? ⇒ Boolean
Constructor Details
Class Attribute Details
.metrics ⇒ Object (readonly)
Returns the value of attribute metrics.
14 15 16 |
# File 'lib/nightfury/identity.rb', line 14 def metrics @metrics end |
.store_as ⇒ Object
Returns the value of attribute store_as.
15 16 17 |
# File 'lib/nightfury/identity.rb', line 15 def store_as @store_as end |
.tags ⇒ Object (readonly)
Returns the value of attribute tags.
14 15 16 |
# File 'lib/nightfury/identity.rb', line 14 def @tags end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
39 40 41 |
# File 'lib/nightfury/identity.rb', line 39 def id @id end |
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
40 41 42 |
# File 'lib/nightfury/identity.rb', line 40 def redis @redis end |
#tags ⇒ Object
Returns the value of attribute tags.
39 40 41 |
# File 'lib/nightfury/identity.rb', line 39 def @tags end |
Class Method Details
.metric(name, type = :value, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/nightfury/identity.rb', line 21 def metric(name, type = :value, ={}) @metrics ||= {} @metrics[name] = {type: type} store_as = [:store_as] ? ":#{[:store_as]}" : 'nil' step = [:step] ? ":#{[:step]}" : ":minute" class_eval <<-ENDOFMETHOD def #{name} @_#{name} ||= METRIC_MAPPINGS[:#{type}].new(:#{name}, redis_key_prefix: key_prefix, store_as: #{store_as}, step: #{step}) end ENDOFMETHOD end |
.name ⇒ Object
17 18 19 |
# File 'lib/nightfury/identity.rb', line 17 def name self.to_s.demodulize.underscore end |
.tag(name, options = {}) ⇒ Object
33 34 35 36 |
# File 'lib/nightfury/identity.rb', line 33 def tag(name, ={}) @tags ||= {} @tags[name] = [:store_as] ? [:store_as] : name end |
Instance Method Details
#key_prefix ⇒ Object
48 49 50 51 52 53 |
# File 'lib/nightfury/identity.rb', line 48 def key_prefix store_name = self.class.store_as ? self.class.store_as : self.class.name tag_ids = generate_tag_ids tag_ids = tag_ids.nil? ? '' : ":#{tag_ids}" "#{store_name}.#{id}#{tag_ids}" end |
#new_record? ⇒ Boolean
55 56 57 |
# File 'lib/nightfury/identity.rb', line 55 def new_record? redis.keys("#{key_prefix}*").empty? end |