Class: Meshchat::Ui::Command::Import

Inherits:
Base
  • Object
show all
Defined in:
lib/meshchat/ui/command/import.rb

Constant Summary

Constants inherited from Base

Base::ADD, Base::ALL_CHAT_LOCK, Base::BIND, Base::CHAT, Base::CONFIG, Base::DISPLAY, Base::EMOTE, Base::EXIT, Base::EXPORT, Base::HELP, Base::IDENTITY, Base::IMPORT, Base::IRB, Base::OFFLINE, Base::ONLINE, Base::PING, Base::PING_ALL, Base::QUIT, Base::REMOVE, Base::RM, Base::ROLL, Base::SEND_DISCONNECT, Base::SERVER, Base::SERVERS, Base::SET, Base::SHARE, Base::WHISPER_LOCK, Base::WHO

Instance Attribute Summary

Attributes inherited from Base

#_input, #_input_factory, #_message_dispatcher, #_message_factory

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Meshchat::Ui::Command::Base

Class Method Details

.descriptionObject



6
7
8
# File 'lib/meshchat/ui/command/import.rb', line 6

def self.description
  'imports an identity file (formatted as json)'
end

Instance Method Details

#command_valid?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/meshchat/ui/command/import.rb', line 32

def command_valid?
  filename.present?
end

#filenameObject



36
37
38
# File 'lib/meshchat/ui/command/import.rb', line 36

def filename
  sub_command
end

#handleObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/meshchat/ui/command/import.rb', line 10

def handle
  if command_valid?
    node = Node.import_from_file(filename)
    if node.valid? && node.persisted?
      Display.success "#{node.alias_name} successfully imported"

      # send the server list to this new node
      node_list = _message_factory.create(Network::Message::NODE_LIST)
      _message_dispatcher.send_message(node: node, message: node_list)
    else
      Display.alert "#{node.alias_name} is invalid"
      Display.alert node.errors.full_messages.join("\n")
    end
  else
    Display.alert usage
  end
end

#usageObject



28
29
30
# File 'lib/meshchat/ui/command/import.rb', line 28

def usage
  'Usage: /import {filename}'
end