Module: Cardio::ScriptLoader::ClassMethods

Included in:
Cardio::ScriptLoader
Defined in:
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 Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#script_nameObject

Returns the value of attribute script_name.



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

def script_name
  @script_name
end

Instance Method Details

#continue?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/cardio/script_loader.rb', line 39

def continue?
  in_application? || in_application_subdirectory?
end

#exec!Object



17
18
19
20
21
22
23
24
25
# File 'lib/cardio/script_loader.rb', line 17

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

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

#exec_scriptObject



35
36
37
# File 'lib/cardio/script_loader.rb', line 35

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

#in_application?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/cardio/script_loader.rb', line 43

def in_application?
  File.exist?(script)
end

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

Returns:

  • (Boolean)


47
48
49
50
# File 'lib/cardio/script_loader.rb', line 47

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



27
28
29
30
31
32
33
# File 'lib/cardio/script_loader.rb', line 27

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



13
14
15
# File 'lib/cardio/script_loader.rb', line 13

def script
  File.join "script", script_name
end