Sha256: 901cb38230637c608a97da2f8f9ab597a0a105b1c3af599c66b71789a043ddcd

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

module Tabs
  module Resolutionable

    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods

      def name
        raise "Must implement #name in the concrete resolution module"
      end

      def serialize
        raise "Must implement #serialize in the concrete resolution module"
      end

      def deserialize
        raise "Must implement #deserialize in the concrete resolution module"
      end

      def from_seconds
        raise "Must implement #from_seconds in the concrete resolution module"
      end

      def to_seconds
        raise "Must implement #to_seconds in the concrete resolution module"
      end

      def add
        raise "Must implement #to_seconds in the concrete resolution module"
      end

      def normalize
        raise "Must implement #normalize in the concrete resolution module"
      end

    end

    def expire(key, timestamp)
      return unless Tabs::Config.expires?(name)
      resolution_ends_at = timestamp.utc.to_i + to_seconds
      expires_at = resolution_ends_at + Tabs::Config.expires_in(name)
      Storage.expireat(key, expires_at)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tabs-1.0.1 lib/tabs/resolutionable.rb
tabs-1.0.0 lib/tabs/resolutionable.rb