Module: Charyf::AppLoader

Extended by:
AppLoader
Included in:
AppLoader
Defined in:
lib/charyf/utils/app_loader.rb

Overview

:nodoc:

Constant Summary collapse

RUBY =
Gem.ruby
EXECUTABLES =
%w(bin/charyf charyf/bin/charyf)

Instance Method Summary collapse

Instance Method Details

#exec_appObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/charyf/utils/app_loader.rb', line 12

def exec_app
  original_cwd = Dir.pwd

  loop do
    if exe = find_executable
      contents = File.read(exe)

      if contents =~ /(APP|ENGINE)_PATH/
        exec RUBY, exe, *ARGV
        break # non reachable, hack to be able to stub exec in the test suite
      end
    end

    # If we exhaust the search there is no executable, this could be a
    # call to generate a new application, so restore the original cwd.
    Dir.chdir(original_cwd) && return if Pathname.new(Dir.pwd).root?

    # Otherwise keep moving upwards in search of an executable.
    Dir.chdir("..")
  end
end

#find_executableObject



34
35
36
# File 'lib/charyf/utils/app_loader.rb', line 34

def find_executable
  EXECUTABLES.find { |exe| File.file?(exe) }
end