Sha256: eaeaf50a8405a073d9ad480e6b6e81e770374e46474ff32164956c877b85f574

Contents?: true

Size: 1.38 KB

Versions: 31

Compression:

Stored size: 1.38 KB

Contents

module Avo
  module Licensing
    class License
      attr_accessor :id
      attr_accessor :response
      attr_accessor :valid
      attr_accessor :payload

      def initialize(response = {})
        @response = response
        @id = response["id"]
        @valid = response["valid"]
        @payload = response["payload"]
      end

      def valid?
        valid
      end

      def invalid?
        !valid?
      end

      def pro?
        id == "pro"
      end

      def error
        @response["error"]
      end

      def properties
        @response.slice("valid", "id", "error").symbolize_keys
      end

      def abilities
        []
      end

      def can(ability)
        abilities.include? ability
      end

      def cant(ability)
        !can ability
      end

      alias_method :has, :can
      alias_method :lacks, :cant

      # Returns if has ability and if is a valid license or app is in development.
      def has_with_trial(ability)
        return can(ability) && valid? if Rails.env.production?

        true
      end

      # Returns if lacks ability and if is a valid license or app is in development.
      def lacks_with_trial(ability)
        !has_with_trial ability
      end

      def name
        if id.present?
          id.humanize
        else
          self.class.to_s.split("::").last.underscore.humanize.gsub " license", ""
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
avo-3.0.1.beta23 lib/avo/licensing/license.rb
avo-3.0.1.beta20 lib/avo/licensing/license.rb
avo-3.0.1.beta21 lib/avo/licensing/license.rb
avo-3.0.1.beta17 lib/avo/licensing/license.rb
avo-3.0.1.beta22 lib/avo/licensing/license.rb
avo-3.0.1.beta18 lib/avo/licensing/license.rb
avo-3.0.1.beta19 lib/avo/licensing/license.rb
avo-3.0.1.beta24 lib/avo/licensing/license.rb
avo-3.0.1.beta15 lib/avo/licensing/license.rb
avo-3.0.1.beta16 lib/avo/licensing/license.rb
avo-3.0.1.beta14 lib/avo/licensing/license.rb
avo-3.0.1.beta12 lib/avo/licensing/license.rb
avo-3.0.1.beta13 lib/avo/licensing/license.rb
avo-3.0.1.beta10 lib/avo/licensing/license.rb
avo-3.0.1.beta11 lib/avo/licensing/license.rb
avo-3.0.0.pre19 lib/avo/licensing/license.rb
avo-3.0.1.beta8 lib/avo/licensing/license.rb
avo-3.0.1.beta9 lib/avo/licensing/license.rb
avo-3.0.1.beta6 lib/avo/licensing/license.rb
avo-3.0.1.beta7 lib/avo/licensing/license.rb