Sha256: cdcf76a91fd2f7a2680f735adb0c2a04d8c1251468307946738332bec30f0627

Contents?: true

Size: 764 Bytes

Versions: 1

Compression:

Stored size: 764 Bytes

Contents

# frozen_string_literal: true

require "gitt"
require "refinements/strings"
require "refinements/structs"

module Rubysmith
  module Configuration
    module Enhancers
      # Dynamically adds Git user if defined.
      class GitUser
        using Refinements::Strings
        using Refinements::Structs

        def initialize git: Gitt::Repository.new
          @git = git
        end

        def call(content) = String(content.author_name).blank? ? content.merge(**user) : content

        private

        attr_reader :git

        def user
          git.get("user.name", "TODO")
             .then { |name| String(name).split }
             .then { |first, last| {author_given_name: first, author_family_name: last} }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubysmith-4.0.1 lib/rubysmith/configuration/enhancers/git_user.rb