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


1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
# File 'lib/warg.rb', line 1876

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