Sha256: ba44c6be2b8960fb57ba25260c3d3e9a8d783cac8c2378fe44e6346e9af9e9ec

Contents?: true

Size: 850 Bytes

Versions: 103

Compression:

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

    module InstanceMethods
      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
end

Version data entries

103 entries across 103 versions & 2 rubygems

Version Path
saucy-0.15.2 lib/saucy/plan.rb
saucy-0.15.1 lib/saucy/plan.rb
saucy-0.15.0 lib/saucy/plan.rb
saucy-0.14.5 lib/saucy/plan.rb
saucy-0.14.3 lib/saucy/plan.rb
saucy-0.10.10 lib/saucy/plan.rb
saucy-0.14.2 lib/saucy/plan.rb
saucy-0.14.1 lib/saucy/plan.rb
saucy-0.14.0 lib/saucy/plan.rb
saucy-0.13.3 lib/saucy/plan.rb
saucy-0.13.2 lib/saucy/plan.rb
saucy-0.10.9 lib/saucy/plan.rb
saucy-0.10.8 lib/saucy/plan.rb
saucy-0.13.1 lib/saucy/plan.rb
saucy-0.13.0 lib/saucy/plan.rb
saucy-0.12.5 lib/saucy/plan.rb
saucy-0.12.4 lib/saucy/plan.rb
saucy-0.12.3 lib/saucy/plan.rb
saucy-0.12.2 lib/saucy/plan.rb
saucy-0.12.1 lib/saucy/plan.rb