Sha256: 43b67b0ab6e4ed889c8c30778f2f59b0ce5a6ef679391917274621e95bb0a379

Contents?: true

Size: 1.28 KB

Versions: 15

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module Mutant
  module License
    class Subscription
      class Commercial < self
        include Concord.new(:authors)

        class Author
          include Concord.new(:email)

          alias_method :to_s, :email
          public :to_s
        end

        def self.from_json(value)
          new(value.fetch('authors').map(&Author.method(:new)).to_set)
        end

        def apply(world)
          candidates = candidates(world)

          if (authors & candidates).any?
            success
          else
            failure(authors, candidates)
          end
        end

      private

        def candidates(world)
          git_author(world).merge(commit_author(world))
        end

        def git_author(world)
          capture(world, %w[git config --get user.email])
        end

        def commit_author(world)
          capture(world, %w[git show --quiet --pretty=format:%ae])
        end

        # ignore :reek:UtilityFunction
        def capture(world, command)
          world
            .capture_stdout(command)
            .fmap(&:chomp)
            .fmap(&Author.method(:new))
            .fmap { |value| Set.new([value]) }
            .from_right { Set.new }
        end

      end # Commercial
    end # Subscription
  end # License
end # Mutant

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
mutant-0.9.14 lib/mutant/license/subscription/commercial.rb
mutant-0.9.13 lib/mutant/license/subscription/commercial.rb
mutant-0.9.12 lib/mutant/license/subscription/commercial.rb
mutant-0.9.11 lib/mutant/license/subscription/commercial.rb
mutant-0.9.10 lib/mutant/license/subscription/commercial.rb
mutant-0.9.9 lib/mutant/license/subscription/commercial.rb
mutant-0.9.8 lib/mutant/license/subscription/commercial.rb
mutant-0.9.7 lib/mutant/license/subscription/commercial.rb
mutant-0.9.6 lib/mutant/license/subscription/commercial.rb
mutant-0.9.5 lib/mutant/license/subscription/commercial.rb
mutant-0.9.4 lib/mutant/license/subscription/commercial.rb
mutant-0.9.3 lib/mutant/license/subscription/commercial.rb
mutant-0.9.2 lib/mutant/license/subscription/commercial.rb
mutant-0.9.1 lib/mutant/license/subscription/commercial.rb
mutant-0.9.0 lib/mutant/license/subscription/commercial.rb