module Pantry
Constants
- SERVER_IDENTITY
Default identity of a
Server
, so as to help differentiate where messages are coming from.- VERSION
Public Class Methods
config()
click to toggle source
Retrieve the current configuration set
# File lib/pantry/config.rb, line 4 def self.config @@config ||= Config.new end
logger()
click to toggle source
Access Pantry’s logger.
# File lib/pantry/logger.rb, line 4 def self.logger @@logger ||= Pantry::Logger.new end
logger=(logger)
click to toggle source
# File lib/pantry/logger.rb, line 8 def self.logger=(logger) @@logger = logger end
reset_config!()
click to toggle source
# File lib/pantry/config.rb, line 8 def self.reset_config! @@config = nil end
reset_ui!()
click to toggle source
# File lib/pantry/ui.rb, line 9 def self.reset_ui! @@ui = nil end
ui(input = $stdin, output = $stdout)
click to toggle source
Public Instance Methods
add_client_command(command_class)
click to toggle source
Register a command object class to be handled only by Clients
# File lib/pantry.rb, line 109 def add_client_command(command_class) ensure_proper_command_class(command_class) check_for_duplicates(client_commands, command_class) client_commands << command_class end
add_server_command(command_class)
click to toggle source
Register a command object class to be handled only by the Server
# File lib/pantry.rb, line 117 def add_server_command(command_class) ensure_proper_command_class(command_class) check_for_duplicates(server_commands, command_class) server_commands << command_class end
all_commands()
click to toggle source
Return all known commands
# File lib/pantry.rb, line 135 def all_commands [client_commands, server_commands].flatten end
check_for_duplicates(command_list, command_class_to_add)
click to toggle source
# File lib/pantry.rb, line 149 def check_for_duplicates(command_list, command_class_to_add) known_commands = command_list.map(&:message_type) if known_commands.include?(command_class_to_add.message_type) raise Pantry::DuplicateCommandError.new("Command with type #{command_class_to_add.message_type} already registered") end end
client_commands()
click to toggle source
Return the list of known Client
command classes
# File lib/pantry.rb, line 125 def client_commands @client_commands ||= [] end
ensure_proper_command_class(command_class)
click to toggle source
# File lib/pantry.rb, line 139 def ensure_proper_command_class(command_class) unless command_class.is_a?(Class) raise Pantry::InvalidCommandError.new("Expected a Class, got an #{command_class.class}") end unless command_class.ancestors.include?(Pantry::Command) raise Pantry::InvalidCommandError.new("Expected a class that's a subclass of Pantry::Command") end end
file_checksum(file_path)
click to toggle source
Calculate the checksum of a file at the given path
# File lib/pantry.rb, line 104 def file_checksum(file_path) Digest::SHA256.file(file_path).hexdigest end
load_plugins()
click to toggle source
Find all installed Pantry
plugin gems. Plugins are defined as gems who contain a file named “pantry/init.rb”.
# File lib/pantry.rb, line 158 def load_plugins Gem.find_latest_files("pantry/init.rb").each do |path| begin gem_path = path.gsub("#{Gem.dir}/gems/", '') Pantry.logger.debug("Installing plugin from #{gem_path}") require path rescue Exception => ex Pantry.logger.warn("Unable to load plugin at #{gem_path}, #{ex.message}") end end end
root(config = Pantry.config)
click to toggle source
The root of all stored Pantry
data for this Server/Client Uses Pantry.config
.root_dir
# File lib/pantry.rb, line 94 def root(config = Pantry.config) Pathname.new(config.root_dir) end
server_commands()
click to toggle source
Return the list of known Server
command classes
# File lib/pantry.rb, line 130 def server_commands @server_commands ||= [] end
set_proc_title(title)
click to toggle source
Update the process’s proc title with the given string
# File lib/pantry.rb, line 99 def set_proc_title(title) $0 = title end