Module: Cardio::ScriptLoader::ClassMethods

Included in:
Cardio::ScriptLoader, Decko::ScriptDeckoLoader
Defined in:
card/lib/cardio/script_loader.rb

Overview

modularize for reusing in decko

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#continue?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'card/lib/cardio/script_loader.rb', line 37

def continue?
  in_application? || in_application_subdirectory?
end

#exec!Object



15
16
17
18
19
20
21
22
23
# File 'card/lib/cardio/script_loader.rb', line 15

def exec!
  cwd = Dir.pwd
  return unless continue?

  exec_script
  recurse cwd
rescue SystemCallError
  # could not chdir, no problem just return
end

#exec_scriptObject



33
34
35
# File 'card/lib/cardio/script_loader.rb', line 33

def exec_script
  exec RUBY, script, *ARGV if in_application?
end

#in_application?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'card/lib/cardio/script_loader.rb', line 41

def in_application?
  File.exist?(script)
end

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

Returns:

  • (Boolean)


45
46
47
48
# File 'card/lib/cardio/script_loader.rb', line 45

def in_application_subdirectory? path=Pathname.new(Dir.pwd)
  File.exist?(File.join(path, script)) ||
    !path.root? && in_application_subdirectory?(path.parent)
end

#recurse(cwd) ⇒ Object



25
26
27
28
29
30
31
# File 'card/lib/cardio/script_loader.rb', line 25

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

#scriptObject



11
12
13
# File 'card/lib/cardio/script_loader.rb', line 11

def script
  File.join("script", "card")
end