Class: MeshChat::Command::Import

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

Constant Summary

Constants inherited from Base

Base::ADD, Base::CHAT, Base::CONFIG, Base::CONNECT, Base::DISPLAY, Base::EXIT, Base::EXPORT, Base::IDENTITY, Base::IMPORT, Base::INIT, Base::IRB, Base::LISTEN, Base::PING, Base::PING_ALL, Base::QUIT, Base::REMOVE, Base::RM, Base::SERVER, Base::SERVERS, Base::SET, Base::SHARE, Base::STOP_LISTENING, Base::WHO

Constants inherited from MeshChat::CLI::Input

MeshChat::CLI::Input::COMMAND, MeshChat::CLI::Input::WHISPER

Instance Attribute Summary

Attributes inherited from Base

#_input

Attributes inherited from MeshChat::CLI::Input

#_input

Instance Method Summary collapse

Methods inherited from MeshChat::CLI::Input

create, #initialize, is_command, is_whisper?

Constructor Details

This class inherits a constructor from MeshChat::CLI::Input

Instance Method Details

#command_valid?Boolean

Returns:

  • (Boolean)


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

def command_valid?
  filename.present?
end

#filenameObject



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

def filename
  sub_command
end

#handleObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/meshchat/command/import.rb', line 4

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

      # send the server list to this new node
      Net::Client.send(
        node: node,
        message: Message::NodeList.new
      )
    else
      Display.alert "#{node.alias_name} is invalid"
      Display.alert node.errors.full_messages.join("\n")
    end
  else
    Display.alert usage
  end
end

#usageObject



24
25
26
# File 'lib/meshchat/command/import.rb', line 24

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