Sha256: 0707801dab7df4b4138e2d66d1c45206f893a6e7ffeed930074915811c2ce53b

Contents?: true

Size: 790 Bytes

Versions: 17

Compression:

Stored size: 790 Bytes

Contents

# frozen_string_literal: true

require "dry/monads"

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

        def call content
          return Success content if content[:author_given_name] || content[:author_family_name]

          name_or content
        end

        private

        def name_or(content) = split(content).or { Success content }

        def split content
          git.get("user.name", nil).fmap do |name|
            next content unless name

            first, last = String(name).split
            content.merge! author_given_name: first, author_family_name: last
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rubysmith-6.6.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-6.5.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-6.4.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-6.3.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-6.2.1 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-6.2.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-6.1.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-6.0.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-5.9.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-5.8.1 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-5.8.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-5.7.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-5.6.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-5.5.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-5.4.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-5.3.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-5.2.0 lib/rubysmith/configuration/transformers/git_user.rb