Module: Rbnotes::Commands

Defined in:
lib/rbnotes/commands.rb,
lib/rbnotes/commands/add.rb,
lib/rbnotes/commands/help.rb,
lib/rbnotes/commands/list.rb,
lib/rbnotes/commands/pick.rb,
lib/rbnotes/commands/show.rb,
lib/rbnotes/commands/delete.rb,
lib/rbnotes/commands/export.rb,
lib/rbnotes/commands/import.rb,
lib/rbnotes/commands/search.rb,
lib/rbnotes/commands/update.rb,
lib/rbnotes/commands/commands.rb,
lib/rbnotes/commands/statistics.rb

Overview

This module defines all command classes of rbnotes. Each command class must be derived from Rbnotes::Commands::Command class.

Defined Under Namespace

Modules: Builtins Classes: Add, Command, Commands, Delete, Export, Help, Import, List, Pick, Search, Show, Statistics, Update

Class Method Summary collapse

Class Method Details

.load(cmd_name) ⇒ Object

Loads a class to perfom the command, then returns an instance of the class.

:call-seq:

load("add")    -> Rbnotes::Commands::Add
load("delete") -> Rbnotes::Commands::Delete
load("export") -> Rbnotes::Commands::Export
load("help")   -> Rbnotes::Commands::Help
load("import") -> Rbnotes::Commnads::Import
load("list")   -> Rbnotes::Commands::List
load("search") -> Rbnotes::Commands::Search
load("show")   -> Rbnotes::Commands::Show
load("update") -> Rbnotes::Commands::Update


269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/rbnotes/commands.rb', line 269

def load(cmd_name)
  cmd_name ||= Builtins.default_cmd_name
  klass_name =  cmd_name.capitalize

  klass = Builtins.command(klass_name)
  if klass.nil?
    begin
      require_relative "commands/#{cmd_name}"
      klass = const_get(klass_name, false)
    rescue LoadError => _
      STDERR.puts "unknown command: #{cmd_name}"
      klass = Builtins.default_cmd
    end
  end
  klass.new
end