Module: Cardio::ScriptLoader::ClassMethods
- Included in:
- Cardio::ScriptLoader
- 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 Attribute Summary collapse
-
#script_name ⇒ Object
Returns the value of attribute script_name.
Instance Method Summary collapse
-
#continue? ⇒ Boolean
-
#exec! ⇒ Object
-
#exec_script ⇒ Object
-
#in_application? ⇒ Boolean
-
#in_application_subdirectory?(path = Pathname.new(Dir.pwd)) ⇒ Boolean
-
#recurse(cwd) ⇒ Object
-
#script ⇒ Object
Instance Attribute Details
#script_name ⇒ Object
Returns the value of attribute script_name.
11 12 13 |
# File 'card/lib/cardio/script_loader.rb', line 11 def script_name @script_name end |
Instance Method Details
#continue? ⇒ Boolean
39 40 41 |
# File 'card/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 'card/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_script ⇒ Object
35 36 37 |
# File 'card/lib/cardio/script_loader.rb', line 35 def exec_script exec RUBY, script, *ARGV if in_application? end |
#in_application? ⇒ Boolean
43 44 45 |
# File 'card/lib/cardio/script_loader.rb', line 43 def in_application? File.exist?(script) end |
#in_application_subdirectory?(path = Pathname.new(Dir.pwd)) ⇒ Boolean
47 48 49 50 |
# File 'card/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 'card/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 |
#script ⇒ Object
13 14 15 |
# File 'card/lib/cardio/script_loader.rb', line 13 def script File.join "script", script_name end |