Module: Warg::Command::CommandMissingHook

Included in:
BehaviorWithoutRegistration::ClassMethods
Defined in:
lib/warg.rb

Instance Method Summary collapse

Instance Method Details

#const_missing(class_name) ⇒ Object



1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
# File 'lib/warg.rb', line 1745

def const_missing(class_name)
  loaded = false

  command_name = Name.new(class_name: class_name.to_s)
  path = "#{command_name.script.tr("-", "_")}.rb"

  Warg.search_paths.each do |warg_path|
    command_path = warg_path.join("commands", path)

    if command_path.exist?
      require command_path
      loaded = true
      break
    end
  end

  if loaded
    Object.const_get(class_name)
  else
    super
  end
end