Class: BellyWash::Resource

Inherits:
Object
  • Object
show all
Includes:
Mixins::Packer
Defined in:
lib/belly_wash/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixins::Packer

included

Constructor Details

#initialize(key:, range:, at:) ⇒ Resource

Returns a new instance of Resource.



8
9
10
11
12
# File 'lib/belly_wash/resource.rb', line 8

def initialize(key:, range:, at:)
  @key = key
  @range = range
  @at = at
end

Instance Attribute Details

#atObject

Returns the value of attribute at.



6
7
8
# File 'lib/belly_wash/resource.rb', line 6

def at
  @at
end

#keyObject

Returns the value of attribute key.



6
7
8
# File 'lib/belly_wash/resource.rb', line 6

def key
  @key
end

#rangeObject

Returns the value of attribute range.



6
7
8
# File 'lib/belly_wash/resource.rb', line 6

def range
  @range
end

Instance Method Details

#full_keyObject



14
15
16
# File 'lib/belly_wash/resource.rb', line 14

def full_key
  [key, range, at.to_i].join(BellyWash.config.separator)
end

#increment(**values) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/belly_wash/resource.rb', line 18

def increment(**values)
  packed = self.class.pack(hash: values)
  BellyWash.client.inc(key: full_key, **packed)
  {
    at => values
  }
end

#valuesObject



26
27
28
29
30
31
32
# File 'lib/belly_wash/resource.rb', line 26

def values
  {
    at => self.class.unpack(
      hash: BellyWash.client.get(key: full_key)
    )
  }
end