Sha256: 51d010f830ad58e036d1e80c057449a599adc4bd108f18bafac708781ec623ec

Contents?: true

Size: 710 Bytes

Versions: 14

Compression:

Stored size: 710 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(content) = content[key] ? Success(content) : user_or(content)

        private

        attr_reader :key

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

Version data entries

14 entries across 14 versions & 1 rubygems

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