Sha256: fae33f4ed790ede58225649dd53b3c0b6c18119f2003cd884fe867a7872c3d5a

Contents?: true

Size: 723 Bytes

Versions: 12

Compression:

Stored size: 723 Bytes

Contents

# frozen_string_literal: true

require "dry/monads"

module Rubysmith
  module Configuration
    module Transformers
      # Dynamically adds Git email if defined.
      class GitEmail
        include Import[:git]
        include Dry::Monads[:result]

        def initialize(key = :author_email, **)
          @key = key
          super(**)
        end

        def call(attributes) = attributes[key] ? Success(attributes) : email_or(attributes)

        private

        attr_reader :key

        def email_or attributes
          git.get("user.email", nil)
             .fmap { |value| value ? attributes.merge!(key => value) : attributes }
             .or { Success attributes }
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rubysmith-7.9.0 lib/rubysmith/configuration/transformers/git_email.rb
rubysmith-7.8.0 lib/rubysmith/configuration/transformers/git_email.rb
rubysmith-7.7.0 lib/rubysmith/configuration/transformers/git_email.rb
rubysmith-7.6.0 lib/rubysmith/configuration/transformers/git_email.rb
rubysmith-7.5.0 lib/rubysmith/configuration/transformers/git_email.rb
rubysmith-7.4.0 lib/rubysmith/configuration/transformers/git_email.rb
rubysmith-7.3.0 lib/rubysmith/configuration/transformers/git_email.rb
rubysmith-7.2.0 lib/rubysmith/configuration/transformers/git_email.rb
rubysmith-7.1.0 lib/rubysmith/configuration/transformers/git_email.rb
rubysmith-7.0.0 lib/rubysmith/configuration/transformers/git_email.rb
rubysmith-6.10.0 lib/rubysmith/configuration/transformers/git_email.rb
rubysmith-6.9.0 lib/rubysmith/configuration/transformers/git_email.rb