Module: Slugforge::Helper::Path
- Defined in:
- lib/slugforge/helper/path.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #deploy_dir(*paths) ⇒ Object
- #project_path(*paths) ⇒ Object
- #project_root ⇒ Object
- #release_dir(*paths) ⇒ Object
- #scripts_dir(*paths) ⇒ Object
- #system_with_path(cmd, path = nil) ⇒ Object
- #templates_dir(*paths) ⇒ Object
- #upstart_dir ⇒ Object
Class Method Details
.included(base) ⇒ Object
6 7 8 9 |
# File 'lib/slugforge/helper/path.rb', line 6 def self.included(base) base.extend ClassMethods base.source_root base.templates_dir end |
Instance Method Details
#deploy_dir(*paths) ⇒ Object
49 50 51 52 |
# File 'lib/slugforge/helper/path.rb', line 49 def deploy_dir(*paths) @deploy_dir ||= File.join('/opt', 'apps', project_name) File.join(@deploy_dir, *paths) end |
#project_path(*paths) ⇒ Object
11 12 13 |
# File 'lib/slugforge/helper/path.rb', line 11 def project_path(*paths) File.join(project_root, *paths) end |
#project_root ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/slugforge/helper/path.rb', line 15 def project_root return @locate_project unless @locate_project.nil? if [:path] && Dir.exist?(File.([:path])) return File.([:path]) end path = File.(Dir.pwd) paths = path.split('/') until paths.empty? if Dir.exist?(File.join(*paths, '.git')) @locate_project = File.join(*paths) return @locate_project end paths.pop end raise error_class, "Invalid path. Unable to find a .git project anywhere in path #{path}. Specify a path with --path." end |
#release_dir(*paths) ⇒ Object
54 55 56 |
# File 'lib/slugforge/helper/path.rb', line 54 def release_dir(*paths) deploy_dir('releases', sha) end |
#scripts_dir(*paths) ⇒ Object
41 42 43 |
# File 'lib/slugforge/helper/path.rb', line 41 def scripts_dir(*paths) File.join(self.class.scripts_dir, *paths) end |
#system_with_path(cmd, path = nil) ⇒ Object
58 59 60 61 62 |
# File 'lib/slugforge/helper/path.rb', line 58 def system_with_path(cmd, path=nil) path ||= [:path] cwd_command = path ? "cd #{path} && " : "" ::Bundler.with_clean_env { system("#{cwd_command}#{cmd}") } end |
#templates_dir(*paths) ⇒ Object
45 46 47 |
# File 'lib/slugforge/helper/path.rb', line 45 def templates_dir(*paths) File.join(self.class.templates_dir, *paths) end |
#upstart_dir ⇒ Object
34 35 36 37 38 39 |
# File 'lib/slugforge/helper/path.rb', line 34 def upstart_dir @upstart_conf_dir ||= project_path('deploy', 'upstart').tap do |dir| FileUtils.mkdir_p(dir) end end |