Sha256: 1387214d4e49347d9036e33ba3e5b8eab87b66396d0da05c50682089d24982cc

Contents?: true

Size: 858 Bytes

Versions: 12

Compression:

Stored size: 858 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 attributes
          if attributes[:author_given_name] || attributes[:author_family_name]
            Success attributes
          else
            name_or attributes
          end
        end

        private

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

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

            first, last = String(name).split
            attributes.merge! author_given_name: first, author_family_name: last
          end
        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_user.rb
rubysmith-7.8.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-7.7.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-7.6.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-7.5.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-7.4.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-7.3.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-7.2.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-7.1.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-7.0.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-6.10.0 lib/rubysmith/configuration/transformers/git_user.rb
rubysmith-6.9.0 lib/rubysmith/configuration/transformers/git_user.rb