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-4.1.0 lib/learn/netrc_interactor.rb
learn-co-4.0.3 lib/learn/netrc_interactor.rb
learn-co-4.0.2 lib/learn/netrc_interactor.rb
learn-co-4.0.1 lib/learn/netrc_interactor.rb
learn-co-4.0.1.pre.1 lib/learn/netrc_interactor.rb
learn-co-4.0.0 lib/learn/netrc_interactor.rb
learn-co-3.9.6 lib/learn/netrc_interactor.rb
learn-co-3.9.5 lib/learn/netrc_interactor.rb
learn-co-3.9.4 lib/learn/netrc_interactor.rb
learn-co-3.9.3 lib/learn/netrc_interactor.rb
learn-co-3.9.2 lib/learn/netrc_interactor.rb
learn-co-3.9.1 lib/learn/netrc_interactor.rb
learn-co-3.9.0 lib/learn/netrc_interactor.rb
learn-co-3.8.13 lib/learn/netrc_interactor.rb
learn-co-3.8.12 lib/learn/netrc_interactor.rb
learn-co-3.8.11 lib/learn/netrc_interactor.rb
learn-co-3.8.10 lib/learn/netrc_interactor.rb
learn-co-3.8.9 lib/learn/netrc_interactor.rb
learn-co-3.8.8 lib/learn/netrc_interactor.rb
learn-co-3.8.7 lib/learn/netrc_interactor.rb