Top Level Namespace
Defined Under Namespace
Classes: CapistranoExtSetHelpers
Instance Method Summary collapse
-
#env_or_ask(variable, question, default = nil) {|value| ... } ⇒ Object
check the environment first for a variable, then asks the user a question to provide the value.
-
#env_or_menu(variable, options, default = nil) {|value| ... } ⇒ Object
checks the environment first for a variable, then asks the user to select its value from the provided list of options.
-
#env_or_set(variable, value = nil, &block) ⇒ Object
use environment variable if provided otherwise use the passed value.
-
#env_set_optional(variable) ⇒ Object
sets variable from environment variable if provided otherwise does nothing.
-
#set_ask(variable, question, default = nil) ⇒ Object
lazy set a variable with env_or_ask.
-
#set_ask_menu(variable, options, default = nil) ⇒ Object
lazy set a variable with env_or_menu.
Instance Method Details
#env_or_ask(variable, question, default = nil) {|value| ... } ⇒ Object
check the environment first for a variable, then asks the user a question to provide the value
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/capistrano/ext/set/helpers.rb', line 75 def env_or_ask(variable, question, default=nil) value = if ENV[variable.to_s].nil? Capistrano::CLI.ui.ask(question) do |q| unless default.nil? q.default = default end end else if ENV[variable.to_s] == /^:/ ENV[variable.to_s].to_sym else ENV[variable.to_s].to_s end end yield(value) if block_given? return value end |
#env_or_menu(variable, options, default = nil) {|value| ... } ⇒ Object
checks the environment first for a variable, then asks the user to select its value from the provided list of options.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/capistrano/ext/set/helpers.rb', line 48 def (variable, , default=nil) question = "( ? ) Select #{variable.to_s}" value = if ENV[variable.to_s].nil? Capistrano::CLI.ui.choose do || unless default.nil? .default = default .prompt = "%s |%s|" % [question,default] else .prompt = question end .each {|c| .choice(c)} .header = question end else if ENV[variable.to_s] == /^:/ ENV[variable.to_s].to_sym else ENV[variable.to_s].to_s end end yield(value) if block_given? return value end |
#env_or_set(variable, value = nil, &block) ⇒ Object
use environment variable if provided otherwise use the passed value
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/capistrano/ext/set/helpers.rb', line 16 def env_or_set(variable, value=nil, &block) value = if ENV[variable.to_s].nil? value else if ENV[variable.to_s] == /^:/ ENV[variable.to_s].to_sym else ENV[variable.to_s].to_s end end set( variable ) { value = block.call if block_given? && value.nil? value = true if value =~ /true/i value = false if value =~ /false/i value } end |
#env_set_optional(variable) ⇒ Object
sets variable from environment variable if provided otherwise does nothing.
36 37 38 39 40 41 42 43 |
# File 'lib/capistrano/ext/set/helpers.rb', line 36 def env_set_optional(variable) value = if ENV[variable.to_s] == /^:/ ENV[variable.to_s].to_sym else ENV[variable.to_s].to_s end set(variable, value) unless value.empty? end |
#set_ask(variable, question, default = nil) ⇒ Object
lazy set a variable with env_or_ask
103 104 105 106 107 108 109 |
# File 'lib/capistrano/ext/set/helpers.rb', line 103 def set_ask(variable, question, default=nil) set(variable) do env_or_ask(variable,question,default) do |value| yield(value) if block_given? end end end |
#set_ask_menu(variable, options, default = nil) ⇒ Object
lazy set a variable with env_or_menu
94 95 96 97 98 99 100 |
# File 'lib/capistrano/ext/set/helpers.rb', line 94 def (variable, , default=nil) set(variable) do (variable,,default) do |value| yield(value) if block_given? end end end |