Sha256: a705e769e16a69a53bbd3b01f37d526c312087d946ccd3df09d19cacee775612

Contents?: true

Size: 1.38 KB

Versions: 152

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

152 entries across 152 versions & 1 rubygems

Version Path
avo-2.32.2 lib/avo/licensing/license.rb
avo-2.32.1 lib/avo/licensing/license.rb
avo-2.32.0 lib/avo/licensing/license.rb
avo-2.31.0 lib/avo/licensing/license.rb
avo-2.30.2 lib/avo/licensing/license.rb
avo-2.30.1 lib/avo/licensing/license.rb
avo-2.30.1.pre4.pr1683 lib/avo/licensing/license.rb
avo-2.30.1.pre3.pr1683 lib/avo/licensing/license.rb
avo-2.30.1.pre2.pr1683 lib/avo/licensing/license.rb
avo-2.30.1.pre1.pr1683 lib/avo/licensing/license.rb
avo-2.30.0 lib/avo/licensing/license.rb
avo-2.29.1 lib/avo/licensing/license.rb
avo-2.29.1.pre.pr1652 lib/avo/licensing/license.rb
avo-2.29.0 lib/avo/licensing/license.rb
avo-2.28.3.pre.pr1646 lib/avo/licensing/license.rb
avo-2.28.2.pre.pr1642 lib/avo/licensing/license.rb
avo-2.28.1.pre.pr1642 lib/avo/licensing/license.rb
avo-2.28.0 lib/avo/licensing/license.rb
avo-2.27.2.pre.pr1606 lib/avo/licensing/license.rb
avo-2.27.1 lib/avo/licensing/license.rb