Sha256: 32fbdc2f98949b4b66af62ae1ddd47ad14199851b14e788af0c2cac44fbc510b

Contents?: true

Size: 1.05 KB

Versions: 34

Compression:

Stored size: 1.05 KB

Contents

# encoding: utf-8

require 'pathname'
require 'rbconfig'

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

    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

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

    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
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
adhearsion-2.6.4 lib/adhearsion/script_ahn_loader.rb
adhearsion-2.6.3 lib/adhearsion/script_ahn_loader.rb
adhearsion-3.0.0.rc1 lib/adhearsion/script_ahn_loader.rb
adhearsion-3.0.0.beta2 lib/adhearsion/script_ahn_loader.rb
adhearsion-3.0.0.beta1 lib/adhearsion/script_ahn_loader.rb
adhearsion-2.6.2 lib/adhearsion/script_ahn_loader.rb
adhearsion-2.6.0 lib/adhearsion/script_ahn_loader.rb
adhearsion-2.5.4 lib/adhearsion/script_ahn_loader.rb
adhearsion-2.5.3 lib/adhearsion/script_ahn_loader.rb
adhearsion-2.5.2 lib/adhearsion/script_ahn_loader.rb
adhearsion-2.5.0 lib/adhearsion/script_ahn_loader.rb
adhearsion-2.4.0 lib/adhearsion/script_ahn_loader.rb
adhearsion-2.4.0.beta3 lib/adhearsion/script_ahn_loader.rb
adhearsion-2.4.0.beta2 lib/adhearsion/script_ahn_loader.rb
adhearsion-2.4.0.beta1 lib/adhearsion/script_ahn_loader.rb
adhearsion-2.3.5 lib/adhearsion/script_ahn_loader.rb
adhearsion-2.3.4 lib/adhearsion/script_ahn_loader.rb
adhearsion-2.3.3 lib/adhearsion/script_ahn_loader.rb
adhearsion-2.3.2 lib/adhearsion/script_ahn_loader.rb
adhearsion-2.3.1 lib/adhearsion/script_ahn_loader.rb