Class: EPC::Command::RefreshSolutionCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- EPC::Command::RefreshSolutionCommand
- Defined in:
- lib/epc/command/refresh_solution_command.rb
Constant Summary
Constants inherited from BaseCommand
BaseCommand::GIVEUP_TICKS, BaseCommand::SLEEP_TIME, BaseCommand::TICKER_TICKS
Instance Attribute Summary
Attributes inherited from BaseCommand
#client, #klass_name, #object_id, #object_type, #options, #target_id, #target_type
Instance Method Summary collapse
Methods inherited from BaseCommand
#check_options, #context_params, #context_params=, #go, include_module, inherited, #initialize, required_options, #say_err
Methods included from PersistentAttributes
#auth_token, #caller_id, #target_url
Constructor Details
This class inherits a constructor from EPC::Command::BaseCommand
Instance Method Details
#execute(path = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/epc/command/refresh_solution_command.rb', line 4 def execute(path = nil) path = "." if path.nil? path = File.(path) path = project_solution_path(path) solution_id, solution_name = infer_solution_context(nil, path) raise FatalError, "Solution could not be inferred" if solution_id.nil? if @options[:prompt_refresh] || @options[:prompt_refresh].nil? proceed = ask_yn("You are about to refresh the #{solution_name} solution. This will retrieve any data that has changed and rename your solution and/or project directories.Are you sure? [Yn]: ") if proceed.upcase == 'N' return 1 end end status, response, = client.get(EPC::Config::SOLUTIONS_PATH + "/#{solution_id}?include=config_values,projects,deployments,deployment_configs") if status.failure? say("Retrieval failed with message [#{response[:message]}]") return status end EPC::Config.(response, path) project_paths = [] response[:projects].each do |project| project_paths << File.join(path, project[:name]) end verified_project_paths = [] project_paths = (project_paths + Dir.glob("#{path}/**").select{|p| File.directory?(p) }).uniq project_paths.each do |project_path| if EPC::Config.is_project_dir?(project_path) verified_project_paths << project_path project_data = response[:projects].detect{|prj| prj[:id] == EPC::Config.get_project_value(project_path, "id") } EPC::Config.(project_data[:id], client, project_path) unless project_data.nil? end end remaining = project_paths - verified_project_paths remaining.each do |r_path| p_name = File.basename(r_path) p_id = response[:projects].detect{|prj| prj[:name] == p_name}[:id] rescue nil if !p_id.nil? unless FileTest.exists?(r_path) mkdir(r_path) end EPC::Config.(p_id, client, r_path) verified_project_paths << r_path end end verified_project_paths.each do |project_path| EPC::Config.update_project_directory(project_path) end EPC::Config.update_solution_directory(path) say("Solution refreshed. You may need to change directories to see the changes.") if @options[:prompt_refresh] || @options[:prompt_refresh].nil? return status end |