Sha256: b2f7d8cffbb1b21c3d1ca664088afaa8cc686fdd6429dcbc506ac0cfdaad3f57
Contents?: true
Size: 1.29 KB
Versions: 9
Compression:
Stored size: 1.29 KB
Contents
require "pathname" module Cardio # help card executable find ./script/card when called from anywhere within deck module ScriptLoader # modularize for reusing in decko module ClassMethods RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + RbConfig::CONFIG["EXEEXT"] def script File.join("script", "card") end def exec! cwd = Dir.pwd return unless continue? exec_script recurse cwd rescue SystemCallError # could not chdir, no problem just return end def recurse cwd 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! unless cwd == Dir.pwd end end def exec_script exec RUBY, script, *ARGV if in_application? end def continue? in_application? || in_application_subdirectory? end def in_application? File.exist?(script) end def in_application_subdirectory? path=Pathname.new(Dir.pwd) File.exist?(File.join(path, script)) || !path.root? && in_application_subdirectory?(path.parent) end end extend ClassMethods end end
Version data entries
9 entries across 9 versions & 1 rubygems