Sha256: 42d0a64933c5425b0b36334b28495e2fdb4d24704465f0e2e5c2bb68afdf0c8e

Contents?: true

Size: 1.57 KB

Versions: 14

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

module Mutant
  module License
    class Subscription
      include Concord.new(:licensed)

      FORMAT = <<~'MESSAGE'
        %<subscription_name>s subscription:
        Licensed:
        %<licensed>s
      MESSAGE

      FAILURE_FORMAT = <<~'MESSAGE'
        Can not validate %<subscription_name>s license.
        Licensed:
        %<expected>s
        Present:
        %<actual>s
      MESSAGE

      # Load value into subscription
      #
      # @param [Object] value
      #
      # @return [Subscription]
      def self.load(world, value)
        {
          'com' => Commercial,
          'oss' => Opensource
        }.fetch(value.fetch('type'))
          .from_json(value.fetch('contents'))
          .apply(world)
      end

      # Subscription self description
      #
      # @return [String]
      def description
        FORMAT % {
          licensed:          licensed.to_a.join("\n"),
          subscription_name: subscription_name
        }
      end

    private

      def failure(expected, actual)
        Either::Left.new(failure_message(expected, actual))
      end

      def success
        Either::Right.new(self)
      end

      def subscription_name
        self.class.name.split('::').last.downcase
      end

      def failure_message(expected, actual)
        FAILURE_FORMAT % {
          actual:            actual.any? ? actual.map(&:to_s).join("\n") : '[none]',
          expected:          expected.map(&:to_s).join("\n"),
          subscription_name: subscription_name
        }
      end
    end # Subscription
  end # License
end # Mutant

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mutant-0.10.17 lib/mutant/license/subscription.rb
mutant-0.10.16 lib/mutant/license/subscription.rb
mutant-0.10.15 lib/mutant/license/subscription.rb
mutant-0.10.14 lib/mutant/license/subscription.rb
mutant-0.10.13 lib/mutant/license/subscription.rb
mutant-0.10.12 lib/mutant/license/subscription.rb
mutant-0.10.11 lib/mutant/license/subscription.rb
mutant-0.10.10 lib/mutant/license/subscription.rb
mutant-0.10.9 lib/mutant/license/subscription.rb
mutant-0.10.8 lib/mutant/license/subscription.rb
mutant-0.10.7 lib/mutant/license/subscription.rb
mutant-0.10.6 lib/mutant/license/subscription.rb
mutant-0.10.5 lib/mutant/license/subscription.rb
mutant-0.10.4 lib/mutant/license/subscription.rb