Sha256: c216bd8d7e8520d21133393dac3d84f09c1c0cac5e8c48a2ec61ef1ebdb20ba4

Contents?: true

Size: 632 Bytes

Versions: 53

Compression:

Stored size: 632 Bytes

Contents

require 'netrc'

module Learn
  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

53 entries across 53 versions & 2 rubygems

Version Path
learn-co-3.8.6 lib/learn/netrc_interactor.rb
learn-co-3.8.5 lib/learn/netrc_interactor.rb
learn-co-3.8.4 lib/learn/netrc_interactor.rb
learn-co-3.8.3 lib/learn/netrc_interactor.rb
learn-co-3.8.2 lib/learn/netrc_interactor.rb
learn-co-3.8.1 lib/learn/netrc_interactor.rb
learn-co-3.8.0 lib/learn/netrc_interactor.rb
learn-co-dev-0.0.2 lib/learn/netrc_interactor.rb
learn-co-dev-0.0.1 lib/learn/netrc_interactor.rb
learn-co-3.8.0.rc1 lib/learn/netrc_interactor.rb
learn-co-3.7.0 lib/learn/netrc_interactor.rb
learn-co-3.6.1 lib/learn/netrc_interactor.rb
learn-co-3.6.0 lib/learn/netrc_interactor.rb
learn-co-3.5.4 lib/learn/netrc_interactor.rb
learn-co-3.5.3 lib/learn/netrc_interactor.rb
learn-co-3.5.2 lib/learn/netrc_interactor.rb
learn-co-3.5.1 lib/learn/netrc_interactor.rb
learn-co-3.5.0 lib/learn/netrc_interactor.rb
learn-co-3.4.5 lib/learn/netrc_interactor.rb
learn-co-3.4.4 lib/learn/netrc_interactor.rb