Class: CapistranoMulticonfigParallel::DependencyTracker
- Inherits:
-
Object
- Object
- CapistranoMulticonfigParallel::DependencyTracker
- Defined in:
- lib/capistrano_multiconfig_parallel/multi_app_helpers/dependency_tracker.rb
Overview
class used to find application dependencies
Instance Attribute Summary collapse
-
#job_manager ⇒ Object
Returns the value of attribute job_manager.
Instance Method Summary collapse
- #add_dependency_app(app_to_deploy, apps_dependencies, applications_to_deploy) ⇒ Object
- #all_websites_return_applications_selected ⇒ Object
- #application_dependencies ⇒ Object
- #check_app_dependency_unique(applications_selected, apps_dependencies, applications_to_deploy, action) ⇒ Object
- #fetch_apps_needed_for_deployment(application, action) ⇒ Object
- #find_apps_and_deps(applications_selected) ⇒ Object
- #get_applications_to_deploy(action, applications_selected) ⇒ Object
-
#initialize(job_manager) ⇒ DependencyTracker
constructor
A new instance of DependencyTracker.
- #print_frameworks_used(app_names, applications_to_deploy, action) ⇒ Object
- #show_frameworks_used(applications_to_deploy, all_frameworks, action) ⇒ Object
Constructor Details
#initialize(job_manager) ⇒ DependencyTracker
Returns a new instance of DependencyTracker.
8 9 10 |
# File 'lib/capistrano_multiconfig_parallel/multi_app_helpers/dependency_tracker.rb', line 8 def initialize(job_manager) @job_manager = job_manager end |
Instance Attribute Details
#job_manager ⇒ Object
Returns the value of attribute job_manager.
6 7 8 |
# File 'lib/capistrano_multiconfig_parallel/multi_app_helpers/dependency_tracker.rb', line 6 def job_manager @job_manager end |
Instance Method Details
#add_dependency_app(app_to_deploy, apps_dependencies, applications_to_deploy) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/capistrano_multiconfig_parallel/multi_app_helpers/dependency_tracker.rb', line 29 def add_dependency_app(app_to_deploy, apps_dependencies, applications_to_deploy) return unless app_to_deploy.present? applications_to_deploy << app_to_deploy return unless app_to_deploy['dependencies'].present? app_to_deploy['dependencies'].each do |dependency| dependency_app = application_dependencies.find { |hash| hash['app'] == dependency } apps_dependencies << dependency_app if dependency_app.present? end end |
#all_websites_return_applications_selected ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/capistrano_multiconfig_parallel/multi_app_helpers/dependency_tracker.rb', line 17 def all_websites_return_applications_selected applications = application_dependencies.map { |hash| hash['app'].camelcase } applications << 'all_frameworks' = CapistranoMulticonfigParallel::InteractiveMenu.new applications_selected = .(applications) applications_selected = applications_selected.gsub("\r\n", '') if applications_selected.present? applications_selected = applications_selected.gsub("\n", '') if applications_selected.present? applications_selected = applications_selected.split(',') if applications_selected.present? applications_selected.present? ? applications_selected : [] end |
#application_dependencies ⇒ Object
12 13 14 15 |
# File 'lib/capistrano_multiconfig_parallel/multi_app_helpers/dependency_tracker.rb', line 12 def application_dependencies deps = CapistranoMulticonfigParallel.configuration.track_dependencies ? CapistranoMulticonfigParallel.configuration.application_dependencies : [] deps.present? && deps.is_a?(Array) ? deps.map(&:stringify_keys) : [] end |
#check_app_dependency_unique(applications_selected, apps_dependencies, applications_to_deploy, action) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/capistrano_multiconfig_parallel/multi_app_helpers/dependency_tracker.rb', line 49 def check_app_dependency_unique(applications_selected, apps_dependencies, applications_to_deploy, action) return applications_to_deploy if applications_selected.blank? || apps_dependencies.blank? || (apps_dependencies.map { |app| app['app'] } - applications_to_deploy.map { |app| app['app'] }).blank? set :apps_dependency_confirmation, CapistranoMulticonfigParallel.ask_confirm("Do you want to #{action} all dependencies also ?", 'Y/N') applications_to_deploy = applications_to_deploy.concat(apps_dependencies) if fetch(:apps_dependency_confirmation).present? && fetch(:apps_dependency_confirmation).downcase == 'y' applications_to_deploy end |
#fetch_apps_needed_for_deployment(application, action) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/capistrano_multiconfig_parallel/multi_app_helpers/dependency_tracker.rb', line 93 def fetch_apps_needed_for_deployment(application, action) applications = [] if @job_manager.custom_command? && @job_manager.multi_apps? apps_selected = all_websites_return_applications_selected applications = get_applications_to_deploy(action, apps_selected) elsif CapistranoMulticonfigParallel.configuration.track_dependencies if application.present? applications = get_applications_to_deploy(action, [application.camelcase]) applications = applications.delete_if { |hash| hash['app'] == application } else applications = [] end else applications = [] end applications end |
#find_apps_and_deps(applications_selected) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/capistrano_multiconfig_parallel/multi_app_helpers/dependency_tracker.rb', line 39 def find_apps_and_deps(applications_selected) applications_to_deploy = [] apps_dependencies = [] applications_selected.each do |app| app_to_deploy = application_dependencies.find { |hash| hash['app'].camelcase == app } add_dependency_app(app_to_deploy, apps_dependencies, applications_to_deploy) end [applications_to_deploy, apps_dependencies] end |
#get_applications_to_deploy(action, applications_selected) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/capistrano_multiconfig_parallel/multi_app_helpers/dependency_tracker.rb', line 56 def get_applications_to_deploy(action, applications_selected) all_frameworks = applications_selected.find { |app| app == 'all_frameworks' } if all_frameworks.present? applications_to_deploy = application_dependencies.map { |hash| hash } else applications_to_deploy, apps_dependencies = find_apps_and_deps(applications_selected) applications_to_deploy = check_app_dependency_unique(applications_selected, apps_dependencies, applications_to_deploy, action) end if applications_to_deploy.present? applications_to_deploy = applications_to_deploy.uniq applications_to_deploy = applications_to_deploy.sort_by { |hash| hash['priority'] } end show_frameworks_used(applications_to_deploy, all_frameworks, action) end |
#print_frameworks_used(app_names, applications_to_deploy, action) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/capistrano_multiconfig_parallel/multi_app_helpers/dependency_tracker.rb', line 83 def print_frameworks_used(app_names, applications_to_deploy, action) app_names.each { |app| puts "#{app}" } set :apps_deploy_confirmation, CapistranoMulticonfigParallel.ask_confirm("Are you sure you want to #{action} these apps?", 'Y/N') if fetch(:apps_deploy_confirmation).blank? || (fetch(:apps_deploy_confirmation).present? && fetch(:apps_deploy_confirmation).downcase != 'y') return [] elsif fetch(:apps_deploy_confirmation).present? && fetch(:apps_deploy_confirmation).downcase == 'y' return applications_to_deploy end end |
#show_frameworks_used(applications_to_deploy, all_frameworks, action) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/capistrano_multiconfig_parallel/multi_app_helpers/dependency_tracker.rb', line 71 def show_frameworks_used(applications_to_deploy, all_frameworks, action) return [] if applications_to_deploy.blank? || applications_to_deploy.size <= 1 puts 'The following frameworks will be used:' app_names = [] if all_frameworks.present? app_names = applications_to_deploy.map { |app| app['app'].camelcase } else app_names = applications_to_deploy.map { |app| application_dependencies.find { |hash| hash['app'] == app['app'] }['app'].camelcase } end print_frameworks_used(app_names, applications_to_deploy, action) end |