Module: Scruber::AppSearcher

Extended by:
AppSearcher
Included in:
AppSearcher
Defined in:
lib/scruber/app_searcher.rb

Constant Summary collapse

RUBY =
Gem.ruby
EXECUTABLES =
["bin/scruber"]

Instance Method Summary collapse

Instance Method Details

#exec_appObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/scruber/app_searcher.rb', line 9

def exec_app
  original_cwd = Dir.pwd

  loop do
    if exe = find_executable
      exec RUBY, exe, *ARGV
      break # non reachable, hack to be able to stub exec in the test suite
    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
  true
end

#find_executableObject



35
36
37
# File 'lib/scruber/app_searcher.rb', line 35

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

#find_scraper(name, app_path) ⇒ Object



28
29
30
31
32
33
# File 'lib/scruber/app_searcher.rb', line 28

def find_scraper(name, app_path)
  [
    File.expand_path('../../scrapers/'+name+'.rb', app_path),
    File.expand_path('../../scrapers/'+name, app_path),
  ].find{|f| File.exists?(f) }
end