Module: BoPeep::Command::CommandMissingHook

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

Instance Method Summary collapse

Instance Method Details

#const_missing(class_name) ⇒ Object



1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
# File 'lib/bopeep.rb', line 1960

def const_missing(class_name)
  loaded = false

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

  BoPeep.search_paths.each do |bopeep_path|
    command_path = bopeep_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