crazy-yard 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +19 -0
  3. data/README.md +438 -0
  4. data/bin/ey +9 -0
  5. data/lib/engineyard.rb +9 -0
  6. data/lib/engineyard/cli.rb +816 -0
  7. data/lib/engineyard/cli/api.rb +98 -0
  8. data/lib/engineyard/cli/recipes.rb +129 -0
  9. data/lib/engineyard/cli/ui.rb +275 -0
  10. data/lib/engineyard/cli/web.rb +85 -0
  11. data/lib/engineyard/config.rb +158 -0
  12. data/lib/engineyard/deploy_config.rb +65 -0
  13. data/lib/engineyard/deploy_config/ref.rb +56 -0
  14. data/lib/engineyard/error.rb +82 -0
  15. data/lib/engineyard/eyrc.rb +59 -0
  16. data/lib/engineyard/repo.rb +105 -0
  17. data/lib/engineyard/serverside_runner.rb +159 -0
  18. data/lib/engineyard/templates.rb +6 -0
  19. data/lib/engineyard/templates/ey.yml.erb +196 -0
  20. data/lib/engineyard/templates/ey_yml.rb +119 -0
  21. data/lib/engineyard/thor.rb +215 -0
  22. data/lib/engineyard/version.rb +4 -0
  23. data/lib/vendor/thor/Gemfile +15 -0
  24. data/lib/vendor/thor/LICENSE.md +20 -0
  25. data/lib/vendor/thor/README.md +35 -0
  26. data/lib/vendor/thor/lib/thor.rb +473 -0
  27. data/lib/vendor/thor/lib/thor/actions.rb +318 -0
  28. data/lib/vendor/thor/lib/thor/actions/create_file.rb +105 -0
  29. data/lib/vendor/thor/lib/thor/actions/create_link.rb +60 -0
  30. data/lib/vendor/thor/lib/thor/actions/directory.rb +119 -0
  31. data/lib/vendor/thor/lib/thor/actions/empty_directory.rb +137 -0
  32. data/lib/vendor/thor/lib/thor/actions/file_manipulation.rb +314 -0
  33. data/lib/vendor/thor/lib/thor/actions/inject_into_file.rb +109 -0
  34. data/lib/vendor/thor/lib/thor/base.rb +652 -0
  35. data/lib/vendor/thor/lib/thor/command.rb +136 -0
  36. data/lib/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +80 -0
  37. data/lib/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
  38. data/lib/vendor/thor/lib/thor/core_ext/ordered_hash.rb +100 -0
  39. data/lib/vendor/thor/lib/thor/error.rb +28 -0
  40. data/lib/vendor/thor/lib/thor/group.rb +282 -0
  41. data/lib/vendor/thor/lib/thor/invocation.rb +172 -0
  42. data/lib/vendor/thor/lib/thor/parser.rb +4 -0
  43. data/lib/vendor/thor/lib/thor/parser/argument.rb +74 -0
  44. data/lib/vendor/thor/lib/thor/parser/arguments.rb +171 -0
  45. data/lib/vendor/thor/lib/thor/parser/option.rb +121 -0
  46. data/lib/vendor/thor/lib/thor/parser/options.rb +218 -0
  47. data/lib/vendor/thor/lib/thor/rake_compat.rb +72 -0
  48. data/lib/vendor/thor/lib/thor/runner.rb +322 -0
  49. data/lib/vendor/thor/lib/thor/shell.rb +88 -0
  50. data/lib/vendor/thor/lib/thor/shell/basic.rb +393 -0
  51. data/lib/vendor/thor/lib/thor/shell/color.rb +148 -0
  52. data/lib/vendor/thor/lib/thor/shell/html.rb +127 -0
  53. data/lib/vendor/thor/lib/thor/util.rb +270 -0
  54. data/lib/vendor/thor/lib/thor/version.rb +3 -0
  55. data/lib/vendor/thor/thor.gemspec +24 -0
  56. data/spec/engineyard/cli/api_spec.rb +50 -0
  57. data/spec/engineyard/cli_spec.rb +28 -0
  58. data/spec/engineyard/config_spec.rb +61 -0
  59. data/spec/engineyard/deploy_config_spec.rb +194 -0
  60. data/spec/engineyard/eyrc_spec.rb +76 -0
  61. data/spec/engineyard/repo_spec.rb +83 -0
  62. data/spec/engineyard_spec.rb +7 -0
  63. data/spec/ey/console_spec.rb +57 -0
  64. data/spec/ey/deploy_spec.rb +435 -0
  65. data/spec/ey/ey_spec.rb +23 -0
  66. data/spec/ey/init_spec.rb +123 -0
  67. data/spec/ey/list_environments_spec.rb +120 -0
  68. data/spec/ey/login_spec.rb +33 -0
  69. data/spec/ey/logout_spec.rb +24 -0
  70. data/spec/ey/logs_spec.rb +36 -0
  71. data/spec/ey/rebuild_spec.rb +18 -0
  72. data/spec/ey/recipes/apply_spec.rb +29 -0
  73. data/spec/ey/recipes/download_spec.rb +43 -0
  74. data/spec/ey/recipes/upload_spec.rb +99 -0
  75. data/spec/ey/rollback_spec.rb +73 -0
  76. data/spec/ey/scp_spec.rb +176 -0
  77. data/spec/ey/servers_spec.rb +209 -0
  78. data/spec/ey/ssh_spec.rb +273 -0
  79. data/spec/ey/status_spec.rb +45 -0
  80. data/spec/ey/timeout_deploy_spec.rb +18 -0
  81. data/spec/ey/web/disable_spec.rb +21 -0
  82. data/spec/ey/web/enable_spec.rb +26 -0
  83. data/spec/ey/web/restart_spec.rb +21 -0
  84. data/spec/ey/whoami_spec.rb +30 -0
  85. data/spec/spec_helper.rb +84 -0
  86. data/spec/support/bundled_ey +7 -0
  87. data/spec/support/fixture_recipes.tgz +0 -0
  88. data/spec/support/git_repos.rb +115 -0
  89. data/spec/support/helpers.rb +330 -0
  90. data/spec/support/matchers.rb +16 -0
  91. data/spec/support/ruby_ext.rb +13 -0
  92. data/spec/support/shared_behavior.rb +278 -0
  93. metadata +411 -0
@@ -0,0 +1,148 @@
1
+ require 'thor/shell/basic'
2
+
3
+ class Thor
4
+ module Shell
5
+ # Inherit from Thor::Shell::Basic and add set_color behavior. Check
6
+ # Thor::Shell::Basic to see all available methods.
7
+ #
8
+ class Color < Basic
9
+ # Embed in a String to clear all previous ANSI sequences.
10
+ CLEAR = "\e[0m"
11
+ # The start of an ANSI bold sequence.
12
+ BOLD = "\e[1m"
13
+
14
+ # Set the terminal's foreground ANSI color to black.
15
+ BLACK = "\e[30m"
16
+ # Set the terminal's foreground ANSI color to red.
17
+ RED = "\e[31m"
18
+ # Set the terminal's foreground ANSI color to green.
19
+ GREEN = "\e[32m"
20
+ # Set the terminal's foreground ANSI color to yellow.
21
+ YELLOW = "\e[33m"
22
+ # Set the terminal's foreground ANSI color to blue.
23
+ BLUE = "\e[34m"
24
+ # Set the terminal's foreground ANSI color to magenta.
25
+ MAGENTA = "\e[35m"
26
+ # Set the terminal's foreground ANSI color to cyan.
27
+ CYAN = "\e[36m"
28
+ # Set the terminal's foreground ANSI color to white.
29
+ WHITE = "\e[37m"
30
+
31
+ # Set the terminal's background ANSI color to black.
32
+ ON_BLACK = "\e[40m"
33
+ # Set the terminal's background ANSI color to red.
34
+ ON_RED = "\e[41m"
35
+ # Set the terminal's background ANSI color to green.
36
+ ON_GREEN = "\e[42m"
37
+ # Set the terminal's background ANSI color to yellow.
38
+ ON_YELLOW = "\e[43m"
39
+ # Set the terminal's background ANSI color to blue.
40
+ ON_BLUE = "\e[44m"
41
+ # Set the terminal's background ANSI color to magenta.
42
+ ON_MAGENTA = "\e[45m"
43
+ # Set the terminal's background ANSI color to cyan.
44
+ ON_CYAN = "\e[46m"
45
+ # Set the terminal's background ANSI color to white.
46
+ ON_WHITE = "\e[47m"
47
+
48
+ # Set color by using a string or one of the defined constants. If a third
49
+ # option is set to true, it also adds bold to the string. This is based
50
+ # on Highline implementation and it automatically appends CLEAR to the end
51
+ # of the returned String.
52
+ #
53
+ # Pass foreground, background and bold options to this method as
54
+ # symbols.
55
+ #
56
+ # Example:
57
+ #
58
+ # set_color "Hi!", :red, :on_white, :bold
59
+ #
60
+ # The available colors are:
61
+ #
62
+ # :bold
63
+ # :black
64
+ # :red
65
+ # :green
66
+ # :yellow
67
+ # :blue
68
+ # :magenta
69
+ # :cyan
70
+ # :white
71
+ # :on_black
72
+ # :on_red
73
+ # :on_green
74
+ # :on_yellow
75
+ # :on_blue
76
+ # :on_magenta
77
+ # :on_cyan
78
+ # :on_white
79
+ def set_color(string, *colors)
80
+ if colors.all? { |color| color.is_a?(Symbol) || color.is_a?(String) }
81
+ ansi_colors = colors.map { |color| lookup_color(color) }
82
+ "#{ansi_colors.join}#{string}#{CLEAR}"
83
+ else
84
+ # The old API was `set_color(color, bold=boolean)`. We
85
+ # continue to support the old API because you should never
86
+ # break old APIs unnecessarily :P
87
+ foreground, bold = colors
88
+ foreground = self.class.const_get(foreground.to_s.upcase) if foreground.is_a?(Symbol)
89
+
90
+ bold = bold ? BOLD : ""
91
+ "#{bold}#{foreground}#{string}#{CLEAR}"
92
+ end
93
+ end
94
+
95
+ protected
96
+
97
+ def can_display_colors?
98
+ stdout.tty?
99
+ end
100
+
101
+ # Overwrite show_diff to show diff with colors if Diff::LCS is
102
+ # available.
103
+ #
104
+ def show_diff(destination, content) #:nodoc:
105
+ if diff_lcs_loaded? && ENV['THOR_DIFF'].nil? && ENV['RAILS_DIFF'].nil?
106
+ actual = File.binread(destination).to_s.split("\n")
107
+ content = content.to_s.split("\n")
108
+
109
+ Diff::LCS.sdiff(actual, content).each do |diff|
110
+ output_diff_line(diff)
111
+ end
112
+ else
113
+ super
114
+ end
115
+ end
116
+
117
+ def output_diff_line(diff) #:nodoc:
118
+ case diff.action
119
+ when '-'
120
+ say "- #{diff.old_element.chomp}", :red, true
121
+ when '+'
122
+ say "+ #{diff.new_element.chomp}", :green, true
123
+ when '!'
124
+ say "- #{diff.old_element.chomp}", :red, true
125
+ say "+ #{diff.new_element.chomp}", :green, true
126
+ else
127
+ say " #{diff.old_element.chomp}", nil, true
128
+ end
129
+ end
130
+
131
+ # Check if Diff::LCS is loaded. If it is, use it to create pretty output
132
+ # for diff.
133
+ #
134
+ def diff_lcs_loaded? #:nodoc:
135
+ return true if defined?(Diff::LCS)
136
+ return @diff_lcs_loaded unless @diff_lcs_loaded.nil?
137
+
138
+ @diff_lcs_loaded = begin
139
+ require 'diff/lcs'
140
+ true
141
+ rescue LoadError
142
+ false
143
+ end
144
+ end
145
+
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,127 @@
1
+ require 'thor/shell/basic'
2
+
3
+ class Thor
4
+ module Shell
5
+ # Inherit from Thor::Shell::Basic and add set_color behavior. Check
6
+ # Thor::Shell::Basic to see all available methods.
7
+ #
8
+ class HTML < Basic
9
+ # The start of an HTML bold sequence.
10
+ BOLD = "font-weight: bold"
11
+
12
+ # Set the terminal's foreground HTML color to black.
13
+ BLACK = 'color: black'
14
+ # Set the terminal's foreground HTML color to red.
15
+ RED = 'color: red'
16
+ # Set the terminal's foreground HTML color to green.
17
+ GREEN = 'color: green'
18
+ # Set the terminal's foreground HTML color to yellow.
19
+ YELLOW = 'color: yellow'
20
+ # Set the terminal's foreground HTML color to blue.
21
+ BLUE = 'color: blue'
22
+ # Set the terminal's foreground HTML color to magenta.
23
+ MAGENTA = 'color: magenta'
24
+ # Set the terminal's foreground HTML color to cyan.
25
+ CYAN = 'color: cyan'
26
+ # Set the terminal's foreground HTML color to white.
27
+ WHITE = 'color: white'
28
+
29
+ # Set the terminal's background HTML color to black.
30
+ ON_BLACK = 'background-color: black'
31
+ # Set the terminal's background HTML color to red.
32
+ ON_RED = 'background-color: red'
33
+ # Set the terminal's background HTML color to green.
34
+ ON_GREEN = 'background-color: green'
35
+ # Set the terminal's background HTML color to yellow.
36
+ ON_YELLOW = 'background-color: yellow'
37
+ # Set the terminal's background HTML color to blue.
38
+ ON_BLUE = 'background-color: blue'
39
+ # Set the terminal's background HTML color to magenta.
40
+ ON_MAGENTA = 'background-color: magenta'
41
+ # Set the terminal's background HTML color to cyan.
42
+ ON_CYAN = 'background-color: cyan'
43
+ # Set the terminal's background HTML color to white.
44
+ ON_WHITE = 'background-color: white'
45
+
46
+ # Set color by using a string or one of the defined constants. If a third
47
+ # option is set to true, it also adds bold to the string. This is based
48
+ # on Highline implementation and it automatically appends CLEAR to the end
49
+ # of the returned String.
50
+ #
51
+ def set_color(string, *colors)
52
+ if colors.all? { |color| color.is_a?(Symbol) || color.is_a?(String) }
53
+ html_colors = colors.map { |color| lookup_color(color) }
54
+ "<span style=\"#{html_colors.join("; ")};\">#{string}</span>"
55
+ else
56
+ color, bold = colors
57
+ html_color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol)
58
+ styles = [html_color]
59
+ styles << BOLD if bold
60
+ "<span style=\"#{styles.join("; ")};\">#{string}</span>"
61
+ end
62
+ end
63
+
64
+ # Ask something to the user and receives a response.
65
+ #
66
+ # ==== Example
67
+ # ask("What is your name?")
68
+ #
69
+ # TODO: Implement #ask for Thor::Shell::HTML
70
+ def ask(statement, color=nil)
71
+ raise NotImplementedError, "Implement #ask for Thor::Shell::HTML"
72
+ end
73
+
74
+ protected
75
+
76
+ def can_display_colors?
77
+ true
78
+ end
79
+
80
+ # Overwrite show_diff to show diff with colors if Diff::LCS is
81
+ # available.
82
+ #
83
+ def show_diff(destination, content) #:nodoc:
84
+ if diff_lcs_loaded? && ENV['THOR_DIFF'].nil? && ENV['RAILS_DIFF'].nil?
85
+ actual = File.binread(destination).to_s.split("\n")
86
+ content = content.to_s.split("\n")
87
+
88
+ Diff::LCS.sdiff(actual, content).each do |diff|
89
+ output_diff_line(diff)
90
+ end
91
+ else
92
+ super
93
+ end
94
+ end
95
+
96
+ def output_diff_line(diff) #:nodoc:
97
+ case diff.action
98
+ when '-'
99
+ say "- #{diff.old_element.chomp}", :red, true
100
+ when '+'
101
+ say "+ #{diff.new_element.chomp}", :green, true
102
+ when '!'
103
+ say "- #{diff.old_element.chomp}", :red, true
104
+ say "+ #{diff.new_element.chomp}", :green, true
105
+ else
106
+ say " #{diff.old_element.chomp}", nil, true
107
+ end
108
+ end
109
+
110
+ # Check if Diff::LCS is loaded. If it is, use it to create pretty output
111
+ # for diff.
112
+ #
113
+ def diff_lcs_loaded? #:nodoc:
114
+ return true if defined?(Diff::LCS)
115
+ return @diff_lcs_loaded unless @diff_lcs_loaded.nil?
116
+
117
+ @diff_lcs_loaded = begin
118
+ require 'diff/lcs'
119
+ true
120
+ rescue LoadError
121
+ false
122
+ end
123
+ end
124
+
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,270 @@
1
+ require 'rbconfig'
2
+
3
+ class Thor
4
+ module Sandbox #:nodoc:
5
+ end
6
+
7
+ # This module holds several utilities:
8
+ #
9
+ # 1) Methods to convert thor namespaces to constants and vice-versa.
10
+ #
11
+ # Thor::Util.namespace_from_thor_class(Foo::Bar::Baz) #=> "foo:bar:baz"
12
+ #
13
+ # 2) Loading thor files and sandboxing:
14
+ #
15
+ # Thor::Util.load_thorfile("~/.thor/foo")
16
+ #
17
+ module Util
18
+
19
+ class << self
20
+
21
+ # Receives a namespace and search for it in the Thor::Base subclasses.
22
+ #
23
+ # ==== Parameters
24
+ # namespace<String>:: The namespace to search for.
25
+ #
26
+ def find_by_namespace(namespace)
27
+ namespace = "default#{namespace}" if namespace.empty? || namespace =~ /^:/
28
+ Thor::Base.subclasses.find { |klass| klass.namespace == namespace }
29
+ end
30
+
31
+ # Receives a constant and converts it to a Thor namespace. Since Thor
32
+ # commands can be added to a sandbox, this method is also responsable for
33
+ # removing the sandbox namespace.
34
+ #
35
+ # This method should not be used in general because it's used to deal with
36
+ # older versions of Thor. On current versions, if you need to get the
37
+ # namespace from a class, just call namespace on it.
38
+ #
39
+ # ==== Parameters
40
+ # constant<Object>:: The constant to be converted to the thor path.
41
+ #
42
+ # ==== Returns
43
+ # String:: If we receive Foo::Bar::Baz it returns "foo:bar:baz"
44
+ #
45
+ def namespace_from_thor_class(constant)
46
+ constant = constant.to_s.gsub(/^Thor::Sandbox::/, "")
47
+ constant = snake_case(constant).squeeze(":")
48
+ constant
49
+ end
50
+
51
+ # Given the contents, evaluate it inside the sandbox and returns the
52
+ # namespaces defined in the sandbox.
53
+ #
54
+ # ==== Parameters
55
+ # contents<String>
56
+ #
57
+ # ==== Returns
58
+ # Array[Object]
59
+ #
60
+ def namespaces_in_content(contents, file=__FILE__)
61
+ old_constants = Thor::Base.subclasses.dup
62
+ Thor::Base.subclasses.clear
63
+
64
+ load_thorfile(file, contents)
65
+
66
+ new_constants = Thor::Base.subclasses.dup
67
+ Thor::Base.subclasses.replace(old_constants)
68
+
69
+ new_constants.map!{ |c| c.namespace }
70
+ new_constants.compact!
71
+ new_constants
72
+ end
73
+
74
+ # Returns the thor classes declared inside the given class.
75
+ #
76
+ def thor_classes_in(klass)
77
+ stringfied_constants = klass.constants.map { |c| c.to_s }
78
+ Thor::Base.subclasses.select do |subclass|
79
+ next unless subclass.name
80
+ stringfied_constants.include?(subclass.name.gsub("#{klass.name}::", ''))
81
+ end
82
+ end
83
+
84
+ # Receives a string and convert it to snake case. SnakeCase returns snake_case.
85
+ #
86
+ # ==== Parameters
87
+ # String
88
+ #
89
+ # ==== Returns
90
+ # String
91
+ #
92
+ def snake_case(str)
93
+ return str.downcase if str =~ /^[A-Z_]+$/
94
+ str.gsub(/\B[A-Z]/, '_\&').squeeze('_') =~ /_*(.*)/
95
+ return $+.downcase
96
+ end
97
+
98
+ # Receives a string and convert it to camel case. camel_case returns CamelCase.
99
+ #
100
+ # ==== Parameters
101
+ # String
102
+ #
103
+ # ==== Returns
104
+ # String
105
+ #
106
+ def camel_case(str)
107
+ return str if str !~ /_/ && str =~ /[A-Z]+.*/
108
+ str.split('_').map { |i| i.capitalize }.join
109
+ end
110
+
111
+ # Receives a namespace and tries to retrieve a Thor or Thor::Group class
112
+ # from it. It first searches for a class using the all the given namespace,
113
+ # if it's not found, removes the highest entry and searches for the class
114
+ # again. If found, returns the highest entry as the class name.
115
+ #
116
+ # ==== Examples
117
+ #
118
+ # class Foo::Bar < Thor
119
+ # def baz
120
+ # end
121
+ # end
122
+ #
123
+ # class Baz::Foo < Thor::Group
124
+ # end
125
+ #
126
+ # Thor::Util.namespace_to_thor_class("foo:bar") #=> Foo::Bar, nil # will invoke default command
127
+ # Thor::Util.namespace_to_thor_class("baz:foo") #=> Baz::Foo, nil
128
+ # Thor::Util.namespace_to_thor_class("foo:bar:baz") #=> Foo::Bar, "baz"
129
+ #
130
+ # ==== Parameters
131
+ # namespace<String>
132
+ #
133
+ def find_class_and_command_by_namespace(namespace, fallback = true)
134
+ if namespace.include?(?:) # look for a namespaced command
135
+ pieces = namespace.split(":")
136
+ command = pieces.pop
137
+ klass = Thor::Util.find_by_namespace(pieces.join(":"))
138
+ end
139
+ unless klass # look for a Thor::Group with the right name
140
+ klass, command = Thor::Util.find_by_namespace(namespace), nil
141
+ end
142
+ if !klass && fallback # try a command in the default namespace
143
+ command = namespace
144
+ klass = Thor::Util.find_by_namespace('')
145
+ end
146
+ return klass, command
147
+ end
148
+ alias find_class_and_task_by_namespace find_class_and_command_by_namespace
149
+
150
+ # Receives a path and load the thor file in the path. The file is evaluated
151
+ # inside the sandbox to avoid namespacing conflicts.
152
+ #
153
+ def load_thorfile(path, content=nil, debug=false)
154
+ content ||= File.binread(path)
155
+
156
+ begin
157
+ Thor::Sandbox.class_eval(content, path)
158
+ rescue Exception => e
159
+ $stderr.puts("WARNING: unable to load thorfile #{path.inspect}: #{e.message}")
160
+ if debug
161
+ $stderr.puts(*e.backtrace)
162
+ else
163
+ $stderr.puts(e.backtrace.first)
164
+ end
165
+ end
166
+ end
167
+
168
+ def user_home
169
+ @@user_home ||= if ENV["HOME"]
170
+ ENV["HOME"]
171
+ elsif ENV["USERPROFILE"]
172
+ ENV["USERPROFILE"]
173
+ elsif ENV["HOMEDRIVE"] && ENV["HOMEPATH"]
174
+ File.join(ENV["HOMEDRIVE"], ENV["HOMEPATH"])
175
+ elsif ENV["APPDATA"]
176
+ ENV["APPDATA"]
177
+ else
178
+ begin
179
+ File.expand_path("~")
180
+ rescue
181
+ if File::ALT_SEPARATOR
182
+ "C:/"
183
+ else
184
+ "/"
185
+ end
186
+ end
187
+ end
188
+ end
189
+
190
+ # Returns the root where thor files are located, depending on the OS.
191
+ #
192
+ def thor_root
193
+ File.join(user_home, ".thor").gsub(/\\/, '/')
194
+ end
195
+
196
+ # Returns the files in the thor root. On Windows thor_root will be something
197
+ # like this:
198
+ #
199
+ # C:\Documents and Settings\james\.thor
200
+ #
201
+ # If we don't #gsub the \ character, Dir.glob will fail.
202
+ #
203
+ def thor_root_glob
204
+ files = Dir["#{escape_globs(thor_root)}/*"]
205
+
206
+ files.map! do |file|
207
+ File.directory?(file) ? File.join(file, "main.thor") : file
208
+ end
209
+ end
210
+
211
+ # Where to look for Thor files.
212
+ #
213
+ def globs_for(path)
214
+ path = escape_globs(path)
215
+ ["#{path}/Thorfile", "#{path}/*.thor", "#{path}/tasks/*.thor", "#{path}/lib/tasks/*.thor"]
216
+ end
217
+
218
+ # Return the path to the ruby interpreter taking into account multiple
219
+ # installations and windows extensions.
220
+ #
221
+ def ruby_command
222
+ @ruby_command ||= begin
223
+ ruby_name = RbConfig::CONFIG['ruby_install_name']
224
+ ruby = File.join(RbConfig::CONFIG['bindir'], ruby_name)
225
+ ruby << RbConfig::CONFIG['EXEEXT']
226
+
227
+ # avoid using different name than ruby (on platforms supporting links)
228
+ if ruby_name != 'ruby' && File.respond_to?(:readlink)
229
+ begin
230
+ alternate_ruby = File.join(RbConfig::CONFIG['bindir'], 'ruby')
231
+ alternate_ruby << RbConfig::CONFIG['EXEEXT']
232
+
233
+ # ruby is a symlink
234
+ if File.symlink? alternate_ruby
235
+ linked_ruby = File.readlink alternate_ruby
236
+
237
+ # symlink points to 'ruby_install_name'
238
+ ruby = alternate_ruby if linked_ruby == ruby_name || linked_ruby == ruby
239
+ end
240
+ rescue NotImplementedError
241
+ # just ignore on windows
242
+ end
243
+ end
244
+
245
+ # escape string in case path to ruby executable contain spaces.
246
+ ruby.sub!(/.*\s.*/m, '"\&"')
247
+ ruby
248
+ end
249
+ end
250
+
251
+ # Returns a string that has had any glob characters escaped.
252
+ # The glob characters are `* ? { } [ ]`.
253
+ #
254
+ # ==== Examples
255
+ #
256
+ # Thor::Util.escape_globs('[apps]') # => '\[apps\]'
257
+ #
258
+ # ==== Parameters
259
+ # String
260
+ #
261
+ # ==== Returns
262
+ # String
263
+ #
264
+ def escape_globs(path)
265
+ path.to_s.gsub(/[*?{}\[\]]/, '\\\\\\&')
266
+ end
267
+
268
+ end
269
+ end
270
+ end