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
- .app_names_from_stages ⇒ Object
- .application_supports_multi_apps?(path = nil) ⇒ Boolean
- .check_stage_path(paths, path) ⇒ Object
- .checks_paths(paths) ⇒ Object
- .configuration_has_valid_path?(hash) ⇒ Boolean
- .fetch_apps_from_file ⇒ Object
- .fetch_paths_from_file ⇒ Object
- .fetch_stages_app(path) ⇒ Object
- .fetch_stages_paths(path) ⇒ Object
- .independent_deploy?(path = nil) ⇒ Boolean
- .multi_apps?(path = nil) ⇒ Boolean
- .sorted_paths(paths) ⇒ Object
- .stages(path = nil) ⇒ Object
- .stages_paths(path) ⇒ Object
- .stages_root(path) ⇒ Object
Class Method Details
.app_names_from_stages ⇒ Object
30 31 32 33 34 35 |
# 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) ⇒ Boolean
22 23 24 |
# 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) ⇒ Object
65 66 67 |
# 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) ⇒ Object
56 57 58 59 |
# 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) ⇒ Boolean
37 38 39 |
# 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 ⇒ Object
26 27 28 |
# 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 ⇒ Object
41 42 43 |
# 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) ⇒ Object
50 51 52 53 54 |
# 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) ⇒ Object
80 81 82 |
# 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) ⇒ Boolean
45 46 47 48 |
# 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) ⇒ Boolean
18 19 20 |
# 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) ⇒ Object
61 62 63 |
# 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) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# 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) ⇒ Object
73 74 75 76 77 78 |
# 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) ⇒ Object
69 70 71 |
# File 'lib/capistrano_multiconfig_parallel/helpers/stages_helper.rb', line 69 def stages_root(path) File.(File.join(path || detect_root, 'config/deploy')) end |