Sha256: 8f6d92fe77a024989eb5cc5d95e99cf6c8424ef26ec891db0aa8e6766bef88a8

Contents?: true

Size: 722 Bytes

Versions: 1

Compression:

Stored size: 722 Bytes

Contents

# This module is intended to be included into any active record
# modle which needs to be aware of how intervals and stored and
# calculated in the db.
#
# Base models must have the following fields: interval_length (integer) and interval_units (integer)
module SolidusSubscriptions
  module Interval
    def self.included(base)
      base.enum interval_units: {
        day: 0,
        week: 1,
        month: 2,
        year: 3
      }
    end

    # Calculates the number of seconds in the interval.
    #
    # @return [Integer] The number of seconds.
    def interval
      ActiveSupport::Duration.new(interval_length, { interval_units.pluralize.to_sym => interval_length })
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_subscriptions-alpha-0.0.4 app/models/solidus_subscriptions/interval.rb