Module: Adhearsion::ScriptAhnLoader

Defined in:
lib/adhearsion/script_ahn_loader.rb

Constant Summary collapse

RUBY =
File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + RbConfig::CONFIG["EXEEXT"]
SCRIPT_AHN =
File.join('script', 'ahn')

Class Method Summary collapse

Class Method Details

.exec_script_ahn!(args = ARGV) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/adhearsion/script_ahn_loader.rb', line 11

def self.exec_script_ahn!(args = ARGV)
  cwd = Dir.pwd
  return unless in_ahn_application? || in_ahn_application_subdirectory?
  exec RUBY, SCRIPT_AHN, *args if in_ahn_application?
  Dir.chdir("..") do
    # Recurse in a chdir block: if the search fails we want to be sure
    # the application is generated in the original working directory.
    exec_script_ahn! unless cwd == Dir.pwd
  end
rescue SystemCallError
  # could not chdir, no problem just return
end

.in_ahn_application?(path = '.') ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/adhearsion/script_ahn_loader.rb', line 24

def self.in_ahn_application?(path = '.')
  Dir.chdir(path) { File.exists? SCRIPT_AHN }
end

.in_ahn_application_subdirectory?(path = Pathname.new(Dir.pwd)) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/adhearsion/script_ahn_loader.rb', line 28

def self.in_ahn_application_subdirectory?(path = Pathname.new(Dir.pwd))
  File.exists?(File.join(path, SCRIPT_AHN)) || !path.root? && in_ahn_application_subdirectory?(path.parent)
end