Class: ThreeScale::Backend::UsageLimit
- Inherits:
-
Object
- Object
- ThreeScale::Backend::UsageLimit
- Extended by:
- Memoizer::Decorator
- Includes:
- Storable
- Defined in:
- lib/3scale/backend/usage_limit.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#metric_id ⇒ Object
Returns the value of attribute metric_id.
-
#period ⇒ Object
Returns the value of attribute period.
-
#plan_id ⇒ Object
Returns the value of attribute plan_id.
-
#service_id ⇒ Object
Returns the value of attribute service_id.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
- .delete(service_id, plan_id, metric_id, period) ⇒ Object
- .load_all(service_id, plan_id) ⇒ Object
- .load_for_affecting_metrics(service_id, plan_id, metric_ids) ⇒ Object
- .load_value(service_id, plan_id, metric_id, period) ⇒ Object
- .save(attributes) ⇒ Object
Instance Method Summary collapse
- #metric_name ⇒ Object
-
#validate(usage_data) ⇒ Object
NOTE: validate can ONLY be called with the guarantee that usage_data will have a matching period key.
Methods included from Memoizer::Decorator
Methods included from Storable
included, #initialize, #storage
Methods included from StorageKeyHelpers
Instance Attribute Details
#metric_id ⇒ Object
Returns the value of attribute metric_id.
8 9 10 |
# File 'lib/3scale/backend/usage_limit.rb', line 8 def metric_id @metric_id end |
#period ⇒ Object
Returns the value of attribute period.
8 9 10 |
# File 'lib/3scale/backend/usage_limit.rb', line 8 def period @period end |
#plan_id ⇒ Object
Returns the value of attribute plan_id.
8 9 10 |
# File 'lib/3scale/backend/usage_limit.rb', line 8 def plan_id @plan_id end |
#service_id ⇒ Object
Returns the value of attribute service_id.
8 9 10 |
# File 'lib/3scale/backend/usage_limit.rb', line 8 def service_id @service_id end |
#value ⇒ Object
Returns the value of attribute value.
8 9 10 |
# File 'lib/3scale/backend/usage_limit.rb', line 8 def value @value end |
Class Method Details
.delete(service_id, plan_id, metric_id, period) ⇒ Object
52 53 54 55 |
# File 'lib/3scale/backend/usage_limit.rb', line 52 def delete(service_id, plan_id, metric_id, period) storage.del(key(service_id, plan_id, metric_id, period)) clear_cache(service_id, plan_id) end |
.load_all(service_id, plan_id) ⇒ Object
23 24 25 26 |
# File 'lib/3scale/backend/usage_limit.rb', line 23 def load_all(service_id, plan_id) metric_ids = Metric.load_all_ids(service_id) generate_for_metrics(service_id, plan_id, metric_ids) end |
.load_for_affecting_metrics(service_id, plan_id, metric_ids) ⇒ Object
29 30 31 |
# File 'lib/3scale/backend/usage_limit.rb', line 29 def load_for_affecting_metrics(service_id, plan_id, metric_ids) generate_for_metrics(service_id, plan_id, metric_ids) end |
.load_value(service_id, plan_id, metric_id, period) ⇒ Object
34 35 36 37 |
# File 'lib/3scale/backend/usage_limit.rb', line 34 def load_value(service_id, plan_id, metric_id, period) raw_value = storage.get(key(service_id, plan_id, metric_id, period)) raw_value and raw_value.to_i end |
.save(attributes) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/3scale/backend/usage_limit.rb', line 39 def save(attributes) service_id = attributes[:service_id] plan_id = attributes[:plan_id] prefix = key_prefix(service_id, plan_id, attributes[:metric_id]) storage.pipelined do PERIODS.each do |period| p_val = attributes[period.to_sym] p_val and storage.set(key_for_period(prefix, period), p_val) end end clear_cache(service_id, plan_id) end |
Instance Method Details
#metric_name ⇒ Object
10 11 12 |
# File 'lib/3scale/backend/usage_limit.rb', line 10 def metric_name Metric.load_name(service_id, metric_id) end |
#validate(usage_data) ⇒ Object
NOTE: validate can ONLY be called with the guarantee that usage_data will have a matching period key.
16 17 18 |
# File 'lib/3scale/backend/usage_limit.rb', line 16 def validate(usage_data) usage_data[period][metric_id].to_i <= value end |