Sha256: b4682997fb17b9f87830f9b36f84fb9d99f898d1f945154992c7c8e8ae47c2a5

Contents?: true

Size: 785 Bytes

Versions: 2

Compression:

Stored size: 785 Bytes

Contents

module Saucy
  module Plan
    extend ActiveSupport::Concern

    included do
      has_many :accounts
      has_many :limits

      validates_presence_of :name

      def self.ordered
        order('price desc')
      end

      def self.paid_by_price
        paid.ordered
      end

      def self.trial
        free.first
      end

      def self.paid
        where('price > 0')
      end

      def self.free
        where('price = 0')
      end
    end

    def free?
      price.zero?
    end

    def billed?
      !free?
    end

    def can_add_more?(limit, amount)
      limits.numbered.named(limit).value > amount
    end

    def allows?(limit)
      limits.boolean.named(limit).allowed?
    end

    def limit(limit_name)
      limits.named(limit_name)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
saucy-0.16.1 lib/saucy/plan.rb
saucy-0.16.0 lib/saucy/plan.rb