Sha256: b792f6428b42e995afb25956912d1f2f3dde3b91b521d0bd29ad6d2166f33a7b

Contents?: true

Size: 698 Bytes

Versions: 4

Compression:

Stored size: 698 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

4 entries across 4 versions & 1 rubygems

Version Path
solidus_subscriptions-alpha-0.0.5 app/models/solidus_subscriptions/interval.rb
solidus_subscriptions-alpha-0.0.3 app/models/solidus_subscriptions/interval.rb
solidus_subscriptions-alpha-0.0.2 app/models/solidus_subscriptions/interval.rb
solidus_subscriptions-alpha-0.0.1 app/models/solidus_subscriptions/interval.rb