Sha256: 7b03b56c5a8dc0c20baa3e860c552ccf1f90e3483c9c369660b19babc4529acc

Contents?: true

Size: 638 Bytes

Versions: 4

Compression:

Stored size: 638 Bytes

Contents

require 'netrc'

module LearnConfig
  class NetrcInteractor
    attr_reader :login, :password, :netrc

    def initialize
      ensure_proper_permissions!
    end

    def read(machine: 'learn-config')
      @netrc = Netrc.read
      @login, @password = netrc[machine]
    end

    def write(machine: 'learn-config', new_login:, new_password:)
      netrc[machine] = new_login, new_password
      netrc.save
    end

    def delete!(machine:)
      @netrc = Netrc.read

      netrc.delete(machine)
      netrc.save
    end

    private

    def ensure_proper_permissions!
      system('chmod 0600 ~/.netrc &>/dev/null')
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
learn-config-1.0.78 lib/learn_config/netrc_interactor.rb
learn-config-1.0.77 lib/learn_config/netrc_interactor.rb
learn-config-1.0.76 lib/learn_config/netrc_interactor.rb
learn-config-1.0.75 lib/learn_config/netrc_interactor.rb