Sha256: 7fe320ab4383cae108053e7619c4ba2ffcb28022509faaf62fdfdbf3b854f865

Contents?: true

Size: 806 Bytes

Versions: 3

Compression:

Stored size: 806 Bytes

Contents

# rubocop:disable all

module Familia::Features

  module Quantizer

    # From Familia::RedisType
    #
    def qstamp(quantum = nil, pattern = nil, now = Familia.now)
      quantum ||= @opts[:quantize] || ttl || 10.minutes
      case quantum
      when Numeric
        # Handle numeric quantum (e.g., seconds, minutes)
      when Array
        quantum, pattern = *quantum
      end
      now ||= Familia.now
      rounded = now - (now % quantum)

      if pattern.nil?
        Time.at(rounded).utc.to_i # 3605 -> 3600
      else
        Time.at(rounded).utc.strftime(pattern || '%H%M') # 3605 -> '1:00'
      end

    end

    # From Familia::Horreum::InstanceMethods:
    #
    #def qstamp(_quantum = nil, pattern = nil, now = Familia.now)
    #  self.class.qstamp ttl, pattern, now
    #end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
familia-1.0.0.pre.rc3 lib/familia/features/quantizer.rb
familia-1.0.0.pre.rc2 lib/familia/features/quantizer.rb
familia-1.0.0.pre.rc1 lib/familia/features/quantizer.rb