capistrano-ext-set-helpers 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.extra_files << "../some/external/dependency.rb"
7
+ #
8
+ # at.libs << ":../some/external"
9
+ #
10
+ # at.add_exception 'vendor'
11
+ #
12
+ # at.add_mapping(/dependency.rb/) do |f, _|
13
+ # at.files_matching(/test_.*rb$/)
14
+ # end
15
+ #
16
+ # %w(TestA TestB).each do |klass|
17
+ # at.extra_class_map[klass] = "test/test_misc.rb"
18
+ # end
19
+ # end
20
+
21
+ # Autotest.add_hook :run_command do |at|
22
+ # system "rake build"
23
+ # end
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2011-09-05
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,7 @@
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/capistrano/ext/set/helpers.rb
7
+ examples/Capfile
@@ -0,0 +1,65 @@
1
+ = capistrano-ext-set-helpers
2
+
3
+ * url: https://github.com/andynu/capistrano-ext-set-helpers
4
+
5
+ == DESCRIPTION:
6
+
7
+ Set helpers allow easier parsing of environment options,
8
+ and top level helpers for the Highline ask/menu methods.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * PROBLEM: Unreleased
13
+
14
+ == SYNOPSIS:
15
+
16
+ env_or_menu(variable, options, default=nil)
17
+ env_or_ask(variable, question, default=nil)
18
+ env_or_set(variable, value=nil, &block)
19
+ env_set_optional(variable)
20
+ set_ask_menu(variable, options, default=nil)
21
+ set_ask(variable, question, default=nil)
22
+
23
+ include:
24
+
25
+ == REQUIREMENTS:
26
+
27
+ * Unkown
28
+
29
+ == INSTALL:
30
+
31
+ * gem install 'capistrano-ext-set-helpers'
32
+
33
+ == DEVELOPERS:
34
+
35
+ After checking out the source, run:
36
+
37
+ $ rake newb
38
+
39
+ This task will install any missing dependencies, run the tests/specs,
40
+ and generate the RDoc.
41
+
42
+ == LICENSE:
43
+
44
+ (The MIT License)
45
+
46
+ Copyright (c) 2011 FIX
47
+
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of this software and associated documentation files (the
50
+ 'Software'), to deal in the Software without restriction, including
51
+ without limitation the rights to use, copy, modify, merge, publish,
52
+ distribute, sublicense, and/or sell copies of the Software, and to
53
+ permit persons to whom the Software is furnished to do so, subject to
54
+ the following conditions:
55
+
56
+ The above copyright notice and this permission notice shall be
57
+ included in all copies or substantial portions of the Software.
58
+
59
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
60
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
61
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
62
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
63
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
64
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
65
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ # Hoe.plugin :compiler
7
+ # Hoe.plugin :gem_prelude_sucks
8
+ # Hoe.plugin :inline
9
+ # Hoe.plugin :racc
10
+ # Hoe.plugin :rubyforge
11
+ Hoe.plugin :gemcutter
12
+
13
+ Hoe.spec 'capistrano-ext-set-helpers' do
14
+ # HEY! If you fill these out in ~/.hoe_template/Rakefile.erb then
15
+ # you'll never have to touch them again!
16
+ # (delete this comment too, of course)
17
+
18
+ developer('Andrew Nutter-Upham', 'andy@ansible.net')
19
+
20
+ # self.rubyforge_name = 'capistrano-ext-set-helpersx' # if different than 'capistrano-ext-set-helpers'
21
+ end
22
+
23
+ # vim: syntax=ruby
@@ -0,0 +1,30 @@
1
+ require 'capistrano/ext/set/helpers'
2
+
3
+ desc "show variables"
4
+ task :show do
5
+
6
+ env_or_set(:user,:default_user_name)
7
+ puts "user = #{user}"
8
+
9
+ ENV['a'] = '1'
10
+ a_from_env = env_or_ask(:a, "What is your user name?")
11
+ b_from_ask = env_or_ask(:b, "How many letters into the alphabet is the letter B")
12
+ set(:a, a_from_env)
13
+ set(:b, b_from_ask)
14
+
15
+ ENV['d'] = '4'
16
+ set_ask(:c, "How many letters into the alphabet is the letter C?")
17
+ set_ask(:d, "How many letters into the alphabet is the letter D?")
18
+ set_ask(:e, "How many letters into the alphabet is the letter E?","5")
19
+
20
+ ENV['f'] = '6'
21
+ set_ask_menu(:f, "How many letters into the alphabet is the letter F?")
22
+ set_ask_menu(:g, %w[7 8 9])
23
+ set_ask_menu(:h, %w[8 9 10], "8")
24
+
25
+ [:a,:b,:c,:d,:e,:f,:g,:h].each do |l|
26
+ puts "#{l} = #{fetch(l)}"
27
+ end
28
+ end
29
+
30
+ # vim: ft=ruby
@@ -0,0 +1,110 @@
1
+ #require 'capistrano'
2
+ #require 'capistrano/configuration/variables'
3
+ #include Capistrano::Configuration::Variables
4
+
5
+ class CapistranoExtSetHelpers
6
+ VERSION = '0.1.0'
7
+ end
8
+
9
+ ###############################################################################
10
+ #
11
+ # Helpers
12
+ #
13
+
14
+ # use environment variable if provided
15
+ # otherwise use the passed value
16
+ def env_or_set(variable, value=nil, &block)
17
+ value = if ENV[variable.to_s].nil?
18
+ value
19
+ else
20
+ if ENV[variable.to_s] == /^:/
21
+ ENV[variable.to_s].to_sym
22
+ else
23
+ ENV[variable.to_s].to_s
24
+ end
25
+ end
26
+ set( variable ) {
27
+ value = block.call if block_given? && value.nil?
28
+ value = true if value =~ /true/i
29
+ value = false if value =~ /false/i
30
+ value
31
+ }
32
+ end
33
+
34
+ # sets variable from environment variable if provided
35
+ # otherwise does nothing.
36
+ def env_set_optional(variable)
37
+ value = if ENV[variable.to_s] == /^:/
38
+ ENV[variable.to_s].to_sym
39
+ else
40
+ ENV[variable.to_s].to_s
41
+ end
42
+ set(variable, value) unless value.empty?
43
+ end
44
+
45
+ # checks the environment first for a variable,
46
+ # then asks the user to select its value from
47
+ # the provided list of options.
48
+ def env_or_menu(variable, options, default=nil)
49
+ question = "( ? ) Select #{variable.to_s}"
50
+ value = if ENV[variable.to_s].nil?
51
+ Capistrano::CLI.ui.choose do |menu|
52
+ unless default.nil?
53
+ menu.default = default
54
+ menu.prompt = "%s |%s|" % [question,default]
55
+ else
56
+ menu.prompt = question
57
+ end
58
+ options.each {|c| menu.choice(c)}
59
+ menu.header = question
60
+ end
61
+ else
62
+ if ENV[variable.to_s] == /^:/
63
+ ENV[variable.to_s].to_sym
64
+ else
65
+ ENV[variable.to_s].to_s
66
+ end
67
+ end
68
+ yield(value) if block_given?
69
+ return value
70
+ end
71
+
72
+ # check the environment first for a variable,
73
+ # then asks the user a question to provide
74
+ # the value
75
+ def env_or_ask(variable, question, default=nil)
76
+ value = if ENV[variable.to_s].nil?
77
+ Capistrano::CLI.ui.ask(question) do |q|
78
+ unless default.nil?
79
+ q.default = default
80
+ end
81
+ end
82
+ else
83
+ if ENV[variable.to_s] == /^:/
84
+ ENV[variable.to_s].to_sym
85
+ else
86
+ ENV[variable.to_s].to_s
87
+ end
88
+ end
89
+ yield(value) if block_given?
90
+ return value
91
+ end
92
+
93
+ # lazy set a variable with env_or_menu
94
+ def set_ask_menu(variable, options, default=nil)
95
+ set(variable) do
96
+ env_or_menu(variable,options,default) do |value|
97
+ yield(value) if block_given?
98
+ end
99
+ end
100
+ end
101
+
102
+ # lazy set a variable with env_or_ask
103
+ def set_ask(variable, question, default=nil)
104
+ set(variable) do
105
+ env_or_ask(variable,question,default) do |value|
106
+ yield(value) if block_given?
107
+ end
108
+ end
109
+ end
110
+
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-ext-set-helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Nutter-Upham
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-05 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hoe
16
+ requirement: &9685320 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.12'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *9685320
25
+ description: ''
26
+ email:
27
+ - andy@ansible.net
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files:
31
+ - History.txt
32
+ - Manifest.txt
33
+ files:
34
+ - .autotest
35
+ - History.txt
36
+ - Manifest.txt
37
+ - README.rdoc
38
+ - Rakefile
39
+ - lib/capistrano/ext/set/helpers.rb
40
+ - examples/Capfile
41
+ homepage:
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --main
46
+ - README.txt
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project: capistrano-ext-set-helpers
63
+ rubygems_version: 1.8.10
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: ''
67
+ test_files: []