Sha256: e98756e428650b25900589770ced0ef9fee746d4065d2b3ed6c171bc10f4eeb3

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

module Mullvadrb
  #
  # Manage Mullvad connect, disconnect and status
  #
  module Connection
    class << self
      def connect
        puts `mullvad connect`
        if $?.success?
          puts I18n.t(:connecting)
        else
          puts I18n.t(:error_connecting)
        end
      end

      def disconnect
        puts `mullvad disconnect`
        if $?.success?
          puts I18n.t(:pulling_the_plug)
        else
          puts I18n.t(:error_disconnecting)
          puts I18n.t(:maybe_connection_inactive)
        end
        sleep 2
        status
      end

      def status
        status = `mullvad status -v`
        if status.start_with?('Disconnected')
          status.gsub!('Disconnected', I18n.t(:disconnected))
                .gsub!(/$/, "\n")
        elsif status.start_with?('Connected')
          status = status.split("\n")
                         .sort
                         .reject { |a| a == 'Connected' }
                         .prepend(I18n.t(:connected))
                         .push("\n")
                         .join("\n")
        elsif status.start_with?('Connecting')
          status = status.split("\n")
                         .sort
                         .reject { |a| a == 'Connecting' }
                         .prepend(I18n.t(:connecting))
                         .push("\n")
                         .join("\n")
        end
        status
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mullvadrb-0.0.5 lib/mullvadrb/connection.rb
mullvadrb-0.0.4 lib/mullvadrb/connection.rb