Class: Redis::TimeSeries::DuplicatePolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/redis/time_series/duplicate_policy.rb

Overview

Duplication policies can be applied to a time series in order to resolve conflicts when adding data that already exists in the series.

Constant Summary collapse

VALID_POLICIES =
%i[
  block
  first
  last
  min
  max
  sum
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(policy) ⇒ DuplicatePolicy

Returns a new instance of DuplicatePolicy.



20
21
22
23
24
25
26
27
# File 'lib/redis/time_series/duplicate_policy.rb', line 20

def initialize(policy)
  policy = policy.to_s.downcase.to_sym
  if VALID_POLICIES.include?(policy)
    @policy = policy
  else
    raise UnknownPolicyError, "#{policy} is not a valid duplicate policy"
  end
end

Instance Attribute Details

#policyObject (readonly)

Returns the value of attribute policy.



18
19
20
# File 'lib/redis/time_series/duplicate_policy.rb', line 18

def policy
  @policy
end

Instance Method Details

#==(other) ⇒ Object



37
38
39
40
# File 'lib/redis/time_series/duplicate_policy.rb', line 37

def ==(other)
  return policy == other.policy if other.is_a?(self.class)
  policy == self.class.new(other).policy
end

#to_a(cmd = 'DUPLICATE_POLICY') ⇒ Object



29
30
31
# File 'lib/redis/time_series/duplicate_policy.rb', line 29

def to_a(cmd = 'DUPLICATE_POLICY')
  [cmd, policy]
end

#to_s(cmd = 'DUPLICATE_POLICY') ⇒ Object



33
34
35
# File 'lib/redis/time_series/duplicate_policy.rb', line 33

def to_s(cmd = 'DUPLICATE_POLICY')
  to_a(cmd).join(' ')
end