Module: CapistranoMulticonfigParallel::StagesHelper

Included in:
ApplicationHelper
Defined in:
lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb

Overview

module used to fetch the stages (code taken from github.com/railsware/capistrano-multiconfig) but refactored to be able to detect stages from multiple paths

Class Method Summary collapse

Class Method Details

.app_names_from_stagesObject



19
20
21
# File 'lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb', line 19

def app_names_from_stages
  independent_deploy? ? fetch_stages_from_file : stages.map { |stage| stage.split(':').reverse[1] }.uniq
end

.check_stage_path(paths, path) ⇒ Object



43
44
45
# File 'lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb', line 43

def check_stage_path(paths, path)
  paths.any? { |another| another != path && another.start_with?(path + ':') }
end

.checks_paths(paths) ⇒ Object



34
35
36
37
# File 'lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb', line 34

def checks_paths(paths)
  paths.reject! { |path| check_stage_path(paths, path) }
  sorted_paths(paths)
end

.fetch_stages_app(path) ⇒ Object



28
29
30
31
32
# File 'lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb', line 28

def fetch_stages_app(path)
  fetch_stages_paths(path) do |paths|
    checks_paths(paths)
  end
end

.fetch_stages_from_fileObject



15
16
17
# File 'lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb', line 15

def fetch_stages_from_file
  configuration.application_dependencies.map { |hash| hash[:app] }
end

.fetch_stages_paths(path) ⇒ Object



58
59
60
# File 'lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb', line 58

def fetch_stages_paths(path)
  stages_paths(path).tap { |paths| yield paths if block_given? }
end

.independent_deploy?Boolean



23
24
25
26
# File 'lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb', line 23

def independent_deploy?
  app_with_no_path = configuration.application_dependencies.find { |hash| hash[:path].blank? }
  configuration.config_dir.present? && app_with_no_path.blank? ? true : false
end

.multi_apps?(path = nil) ⇒ Boolean



11
12
13
# File 'lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb', line 11

def multi_apps?(path = nil)
  path.blank? && independent_deploy? ? true : stages(path).find { |stage| stage.include?(':') }.present?
end

.sorted_paths(paths) ⇒ Object



39
40
41
# File 'lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb', line 39

def sorted_paths(paths)
  paths.present? ? paths.uniq.sort : paths
end

.stages(path = nil) ⇒ Object



7
8
9
# File 'lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb', line 7

def stages(path = nil)
  path.blank? && independent_deploy? ? fetch_stages_from_file : fetch_stages_app(path)
end

.stages_paths(path) ⇒ Object



51
52
53
54
55
56
# File 'lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb', line 51

def stages_paths(path)
  root_stages = stages_root(path)
  Dir["#{root_stages}/**/*.rb"].map do |file|
    file.slice(root_stages.size + 1..-4).tr('/', ':')
  end
end

.stages_root(path) ⇒ Object



47
48
49
# File 'lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb', line 47

def stages_root(path)
  File.expand_path(File.join(path || detect_root, 'config/deploy'))
end