Sha256: 082660869f6430062149454005addf4255660c46b10746a16586dfd26065104e

Contents?: true

Size: 734 Bytes

Versions: 2

Compression:

Stored size: 734 Bytes

Contents

# frozen_string_literal: true

require "dry/monads"

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

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

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

        private

        attr_reader :key

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubysmith-6.10.0 lib/rubysmith/configuration/transformers/git_hub_user.rb
rubysmith-6.9.0 lib/rubysmith/configuration/transformers/git_hub_user.rb