module CapistranoMulticonfigParallel::StagesHelper

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

Public Instance Methods

app_names_from_stages() click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb, line 30
def app_names_from_stages
   app_names = fetch_apps_from_file
   new_apps = stages.map { |stage| stage.split(':').reverse[1] }.compact
   app_names.concat(new_apps).uniq
   app_names
end
application_supports_multi_apps?(path = nil) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb, line 22
def application_supports_multi_apps?(path = nil)
  fetch_stages_app(path).find { |stage| stage.include?(':') }.present?
end
check_stage_path(paths, path) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb, line 65
def check_stage_path(paths, path)
  paths.any? { |another| another != path && another.start_with?(path + ':') }
end
checks_paths(paths) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb, line 56
def checks_paths(paths)
  paths.reject! { |path| check_stage_path(paths, path) }
  sorted_paths(paths)
end
configuration_has_valid_path?(hash) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb, line 37
def configuration_has_valid_path?(hash)
   hash[:path].present? && File.directory?(hash[:path])
end
fetch_apps_from_file() click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb, line 26
def fetch_apps_from_file
  configuration.application_dependencies.map { |hash| hash[:app] }
end
fetch_paths_from_file() click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb, line 41
def fetch_paths_from_file
  configuration.application_dependencies.select { |hash| configuration_has_valid_path?(hash) }.map{ |hash| hash[:path] }
end
fetch_stages_app(path) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb, line 50
def fetch_stages_app(path)
  fetch_stages_paths(path) do |paths|
    checks_paths(paths)
  end
end
fetch_stages_paths(path) { |paths| ... } click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb, line 80
def fetch_stages_paths(path)
  stages_paths(path).tap { |paths| yield paths if block_given? }
end
independent_deploy?(path = nil) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb, line 45
def independent_deploy?(path = nil)
  app_with_path = configuration.application_dependencies.find { |hash| configuration_has_valid_path?(hash).present? }
  configuration.config_dir.present? && app_with_path.present? && (path.nil? || (path.present? && fetch_paths_from_file.include?(path))) ? true : false
end
multi_apps?(path = nil) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb, line 18
def multi_apps?(path = nil)
  independent_deploy?(path) ? true : stages(path).find { |stage| stage.include?(':') }.present?
end
sorted_paths(paths) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb, line 61
def sorted_paths(paths)
  paths.present? ? paths.uniq.sort : paths
end
stages(path = nil) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb, line 7
def stages(path = nil)
  stages = path.present? ? fetch_stages_app(path) : []
  if path.blank?
    root =  detect_root rescue nil
    if root.present?
      stages = stages.concat(fetch_stages_app(nil))
    end
  end
  stages
end
stages_paths(path) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb, line 73
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) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb, line 69
def stages_root(path)
  File.expand_path(File.join(path || detect_root, 'config/deploy'))
end