Class: RecordOnChain::CommandLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/record_on_chain/command_loader.rb

Class Method Summary collapse

Class Method Details

.load(name, dirpath = COMMANDS_DIRPATH, argv = ARGV, cli = Cli.new) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/record_on_chain/command_loader.rb', line 6

def self.load( name, dirpath= COMMANDS_DIRPATH, argv= ARGV, cli= Cli.new )
  # command name not found
  raise "Command name not found. See 'rochain help'" if name.nil?
  # except abstract sourcefile
  return nil if name.start_with?("abstract","mod")
  # expand command file path
  filepath = File.expand_path( name, dirpath ) << ".rb"
  # check file existance
  return nil unless File.file?( filepath )
  # require command file
  require( filepath )
  # generate object
  class_name = "RecordOnChain::Commands::#{name.capitalize}"
  return Object.const_get( class_name ).new( argv , cli )
end