Class: ThreeScale::Backend::Usage

Inherits:
Object
  • Object
show all
Defined in:
lib/3scale/backend/usage.rb

Class Method Summary collapse

Class Method Details

.application_usage(application, timestamp) ⇒ Object



5
6
7
8
9
10
# File 'lib/3scale/backend/usage.rb', line 5

def application_usage(application, timestamp)
  usage(application.usage_limits, timestamp) do |metric_id, instance_period|
    Stats::Keys.application_usage_value_key(
        application.service_id, application.id, metric_id, instance_period)
  end
end

.application_usage_for_limits(application, timestamp, usage_limits) ⇒ Object



12
13
14
15
16
17
# File 'lib/3scale/backend/usage.rb', line 12

def application_usage_for_limits(application, timestamp, usage_limits)
  usage(usage_limits, timestamp) do |metric_id, instance_period|
    Stats::Keys.application_usage_value_key(
      application.service_id, application.id, metric_id, instance_period)
  end
end

.get_from(usage_str, current_value = 0) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/3scale/backend/usage.rb', line 23

def get_from(usage_str, current_value = 0)
  if is_set? usage_str
    usage_str[1..-1].to_i
  else
    # Note: this relies on the fact that NilClass#to_i returns 0
    # and String#to_i returns 0 on non-numeric contents.
    current_value + usage_str.to_i
  end
end

.is_set?(usage_str) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/3scale/backend/usage.rb', line 19

def is_set?(usage_str)
  usage_str && usage_str[0] == '#'.freeze
end