Module: Negroku::Modes::Stage
- Extended by:
- Stage
- Includes:
- Capistrano::DSL
- Included in:
- Stage
- Defined in:
- lib/negroku/modes/stage.rb
Instance Method Summary collapse
- #add ⇒ Object
- #add_stage_file(data) ⇒ Object
- #ask_domains ⇒ Object
- #ask_server_url ⇒ Object
- #ask_set_vars ⇒ Object
-
#ask_stage ⇒ Object
Ask the stage name.
- #get_remote_branches(fetch = false) ⇒ Object
- #remove_stage(stage = nil) ⇒ Object
- #select_branch ⇒ Object
Instance Method Details
#add ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/negroku/modes/stage.rb', line 5 def add config = { stage_name: ask_stage, branch: select_branch, domains: ask_domains, server_url: ask_server_url } add_stage_file config if ask_set_vars load deploy_config_path Negroku::Modes::Env.bulk(config[:stage_name]) end end |
#add_stage_file(data) ⇒ Object
25 26 27 28 29 |
# File 'lib/negroku/modes/stage.rb', line 25 def add_stage_file(data) destination = AppDirectory.deploy.join("#{data[:stage_name]}.rb") build_template("templates/stage.rb.erb", destination, binding) end |
#ask_domains ⇒ Object
36 37 38 39 |
# File 'lib/negroku/modes/stage.rb', line 36 def ask_domains question = I18n.t :ask_domains, scope: :negroku Ask.input question end |
#ask_server_url ⇒ Object
31 32 33 34 |
# File 'lib/negroku/modes/stage.rb', line 31 def ask_server_url question = I18n.t :ask_server_url, scope: :negroku Ask.input question end |
#ask_set_vars ⇒ Object
20 21 22 23 |
# File 'lib/negroku/modes/stage.rb', line 20 def ask_set_vars question = I18n.t :ask_set_vars, scope: :negroku Ask.confirm question, default: false end |
#ask_stage ⇒ Object
Ask the stage name
60 61 62 63 64 65 |
# File 'lib/negroku/modes/stage.rb', line 60 def ask_stage question = I18n.t :ask_stage_name, scope: :negroku stage_name = Ask.input question raise "Stage name required" if stage_name.empty? stage_name end |
#get_remote_branches(fetch = false) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/negroku/modes/stage.rb', line 48 def get_remote_branches(fetch=false) %x(git fetch) if fetch branches = [] %x(git branch -r).split.each do |branch| next unless branch.start_with? 'origin' branches << branch.split('/', 2)[1] unless branch =~ /HEAD/ end branches.uniq end |
#remove_stage(stage = nil) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/negroku/modes/stage.rb', line 67 def remove_stage(stage=nil) current_stages = Dir[File.join(@deploy_dir, '*.rb')].map(){|f| File.basename(f)} if stage.nil? selections = Ask.checkbox "What stages you want to remove", current_stages stages_to_delete = selections.map.with_index { |v, i| current_stages[i] if v}.compact else stages_to_delete = ["#{stage}.rb"] end if stages_to_delete.count > 0 stages_to_delete.each do |s| path_to_delete = File.join(@deploy_dir, s) begin FileUtils.rm(path_to_delete) rescue puts "The stage '#{s}' doesn't exist" end end else puts "Nothing to do" end end |
#select_branch ⇒ Object
41 42 43 44 45 46 |
# File 'lib/negroku/modes/stage.rb', line 41 def select_branch question = I18n.t :select_branch, scope: :negroku branches = get_remote_branches answer = Ask.list question, branches return branches[answer] unless branches.empty? end |