Module: DepsMethods::ClassMethods
- Defined in:
- lib/deps_methods.rb
Instance Method Summary collapse
- #autoload_all(dir) ⇒ Object
- #fix ⇒ Object
- #lib ⇒ Object
- #path_to_constance_name_for_autoload(path) ⇒ Object (also: #to_constance)
- #project_lib ⇒ Object
- #require_all(dir) ⇒ Object
- #require_all_in_lib(*args) ⇒ Object
- #require_and_include_all_guard_helpers ⇒ Object
- #require_file(p) ⇒ Object
- #require_or_autoload_all(dir) ⇒ Object
- #spec ⇒ Object
- #use_capistrano ⇒ Object
Instance Method Details
#autoload_all(dir) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/deps_methods.rb', line 87 def autoload_all(dir) require_or_autoload_all(dir) do |p| full_namespace, autoload_name = to_constance(p) full_namespace.autoload autoload_name, p end end |
#fix ⇒ Object
29 30 31 32 33 |
# File 'lib/deps_methods.rb', line 29 def fix if defined? spec File.join(spec, 'fixtures') end end |
#lib ⇒ Object
17 18 19 20 21 |
# File 'lib/deps_methods.rb', line 17 def lib if defined? root File.join(root, 'lib') end end |
#path_to_constance_name_for_autoload(path) ⇒ Object Also known as: to_constance
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/deps_methods.rb', line 94 def path_to_constance_name_for_autoload(path) path_in_lib = path.gsub(%r{^.*lib/}, "").gsub(%r{\.\w*$}, '') result = path_in_lib.split("\/").map(&:camelize) autoload_name = result.last.to_sym full_namespace = Object result[0..-2].each do |namespace| full_namespace = full_namespace.const_get(namespace.to_sym) end return full_namespace, autoload_name end |
#project_lib ⇒ Object
13 14 15 |
# File 'lib/deps_methods.rb', line 13 def project_lib @project_lib = lib || RoCommands.lib end |
#require_all(dir) ⇒ Object
66 67 68 69 70 |
# File 'lib/deps_methods.rb', line 66 def require_all(dir) require_or_autoload_all(dir) do |p| require_file(p) end end |
#require_all_in_lib(*args) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/deps_methods.rb', line 42 def require_all_in_lib(*args) opts = args. opts[:ignore] ||= %r{(.+)\.rb\(deprecated\)$} ::Find.find(project_lib) do |p| unless p.match(opts[:ignore]) if test(?f, p) and p.match(%r{(.+)\.rb}) Out.table("require", "#{p} file:#{File.basename __FILE__} line:#{__LINE__}") require p end end end end |
#require_and_include_all_guard_helpers ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/deps_methods.rb', line 55 def require_and_include_all_guard_helpers ::Find.find(File.join(project_lib, "guard_helpers")) do |p| if p.match(%r{(.+)\.rb$}) require p basename = File.basename(p).gsub(%r{\.\w+$}, "") ::Guard::Build.send :include, ::GuardHelpers.const_get(:"#{basename.camelize}") end end end |
#require_file(p) ⇒ Object
108 109 110 111 112 |
# File 'lib/deps_methods.rb', line 108 def require_file(p) basename = File.basename(p).gsub(%r{\.\w+$}, "") Out.table "require", " #{basename} ", "file:#{File.basename __FILE__} line:#{__LINE__}" require p end |
#require_or_autoload_all(dir) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/deps_methods.rb', line 72 def require_or_autoload_all(dir) ds = ::Find.find(project_lib).select do |p| test(?d, p) end d = ds.grep(%r{#{dir}$}).compact.first if d ::Find.find(d) do |p| if test(?f, p) and p.match(%r{\.rb$}) yield p end end end end |
#spec ⇒ Object
23 24 25 26 27 |
# File 'lib/deps_methods.rb', line 23 def spec if defined? root File.join(root, 'spec') end end |
#use_capistrano ⇒ Object
35 36 37 38 39 40 |
# File 'lib/deps_methods.rb', line 35 def use_capistrano require 'capistrano/all' require 'capistrano/setup' require 'capistrano/deploy' require 'sshkit/dsl' end |