Sha256: b9d2673547b6ca7fe007a6b3fc3a9662eba91e195c8bba98da06783faafd12c5

Contents?: true

Size: 1.38 KB

Versions: 23

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

23 entries across 23 versions & 1 rubygems

Version Path
avo-2.53.0 lib/avo/licensing/license.rb
avo-2.52.0 lib/avo/licensing/license.rb
avo-2.49.0 lib/avo/licensing/license.rb
avo-2.48.0 lib/avo/licensing/license.rb
avo-2.47.0 lib/avo/licensing/license.rb
avo-2.46.0 lib/avo/licensing/license.rb
avo-2.45.0 lib/avo/licensing/license.rb
avo-2.44.0 lib/avo/licensing/license.rb
avo-2.43.0 lib/avo/licensing/license.rb
avo-2.42.2 lib/avo/licensing/license.rb
avo-2.42.1 lib/avo/licensing/license.rb
avo-2.42.0 lib/avo/licensing/license.rb
avo-2.41.0 lib/avo/licensing/license.rb
avo-2.40.0 lib/avo/licensing/license.rb
avo-2.39.0 lib/avo/licensing/license.rb
avo-2.38.0 lib/avo/licensing/license.rb
avo-2.37.2 lib/avo/licensing/license.rb
avo-2.37.1 lib/avo/licensing/license.rb
avo-2.37.0 lib/avo/licensing/license.rb
avo-2.36.3 lib/avo/licensing/license.rb