Sha256: 28e3dc4eff12e9bf7f495595d6c7d9a74334409798601e6cb538ec2f94118eaa

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

module Qcmd
  class Context
    attr_accessor :machine, :workspace, :workspace_connected

    def reset
      disconnect_machine
      disconnect_workspace
    end

    def disconnect_machine
      self.machine = nil
    end

    def disconnect_workspace
      self.workspace = nil
      self.workspace_connected = false
    end

    def machine_connected?
      !machine.nil?
    end

    def workspace_connected?
      !!workspace_connected
    end

    def connection_state
      if !machine_connected?
        :none
      elsif !workspace_connected?
        :machine
      else
        :workspace
      end
    end

    def print_workspace_list
      Qcmd.print Qcmd.centered_text(" Workspaces ", '-')
      Qcmd.print

      machine.workspaces.each_with_index do |ws, n|
        Qcmd.print "#{ n + 1 }. #{ ws.name }#{ ws.passcode? ? ' [PROTECTED]' : ''}"
      end

      Qcmd.print
      Qcmd.print_wrapped('Type `use "WORKSPACE_NAME" PASSCODE` to load a workspace. Passcode is optional.')
      Qcmd.print
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qcmd-0.1.7 lib/qcmd/context.rb