bundler-maglev- 1.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. data/.gitignore +22 -0
  2. data/.travis.yml +32 -0
  3. data/CHANGELOG.md +805 -0
  4. data/ISSUES.md +62 -0
  5. data/LICENSE +23 -0
  6. data/README.md +29 -0
  7. data/Rakefile +212 -0
  8. data/UPGRADING.md +103 -0
  9. data/bin/bundle +22 -0
  10. data/bundler.gemspec +30 -0
  11. data/lib/bundler.rb +286 -0
  12. data/lib/bundler/capistrano.rb +11 -0
  13. data/lib/bundler/cli.rb +520 -0
  14. data/lib/bundler/definition.rb +438 -0
  15. data/lib/bundler/dependency.rb +134 -0
  16. data/lib/bundler/deployment.rb +58 -0
  17. data/lib/bundler/dsl.rb +257 -0
  18. data/lib/bundler/environment.rb +47 -0
  19. data/lib/bundler/gem_helper.rb +151 -0
  20. data/lib/bundler/gem_installer.rb +9 -0
  21. data/lib/bundler/gem_tasks.rb +2 -0
  22. data/lib/bundler/graph.rb +130 -0
  23. data/lib/bundler/index.rb +138 -0
  24. data/lib/bundler/installer.rb +97 -0
  25. data/lib/bundler/lazy_specification.rb +74 -0
  26. data/lib/bundler/lockfile_parser.rb +108 -0
  27. data/lib/bundler/remote_specification.rb +59 -0
  28. data/lib/bundler/resolver.rb +464 -0
  29. data/lib/bundler/rubygems_ext.rb +237 -0
  30. data/lib/bundler/rubygems_integration.rb +349 -0
  31. data/lib/bundler/runtime.rb +152 -0
  32. data/lib/bundler/settings.rb +115 -0
  33. data/lib/bundler/setup.rb +23 -0
  34. data/lib/bundler/shared_helpers.rb +71 -0
  35. data/lib/bundler/source.rb +708 -0
  36. data/lib/bundler/spec_set.rb +135 -0
  37. data/lib/bundler/templates/Executable +16 -0
  38. data/lib/bundler/templates/Gemfile +4 -0
  39. data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  40. data/lib/bundler/templates/newgem/Rakefile.tt +1 -0
  41. data/lib/bundler/templates/newgem/bin/newgem.tt +3 -0
  42. data/lib/bundler/templates/newgem/gitignore.tt +4 -0
  43. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +9 -0
  44. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  45. data/lib/bundler/templates/newgem/newgem.gemspec.tt +24 -0
  46. data/lib/bundler/ui.rb +73 -0
  47. data/lib/bundler/vendor/thor.rb +358 -0
  48. data/lib/bundler/vendor/thor/actions.rb +314 -0
  49. data/lib/bundler/vendor/thor/actions/create_file.rb +105 -0
  50. data/lib/bundler/vendor/thor/actions/create_link.rb +57 -0
  51. data/lib/bundler/vendor/thor/actions/directory.rb +93 -0
  52. data/lib/bundler/vendor/thor/actions/empty_directory.rb +134 -0
  53. data/lib/bundler/vendor/thor/actions/file_manipulation.rb +270 -0
  54. data/lib/bundler/vendor/thor/actions/inject_into_file.rb +109 -0
  55. data/lib/bundler/vendor/thor/base.rb +576 -0
  56. data/lib/bundler/vendor/thor/core_ext/file_binary_read.rb +9 -0
  57. data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  58. data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +100 -0
  59. data/lib/bundler/vendor/thor/error.rb +30 -0
  60. data/lib/bundler/vendor/thor/group.rb +273 -0
  61. data/lib/bundler/vendor/thor/invocation.rb +168 -0
  62. data/lib/bundler/vendor/thor/parser.rb +4 -0
  63. data/lib/bundler/vendor/thor/parser/argument.rb +67 -0
  64. data/lib/bundler/vendor/thor/parser/arguments.rb +161 -0
  65. data/lib/bundler/vendor/thor/parser/option.rb +120 -0
  66. data/lib/bundler/vendor/thor/parser/options.rb +175 -0
  67. data/lib/bundler/vendor/thor/rake_compat.rb +66 -0
  68. data/lib/bundler/vendor/thor/runner.rb +309 -0
  69. data/lib/bundler/vendor/thor/shell.rb +88 -0
  70. data/lib/bundler/vendor/thor/shell/basic.rb +302 -0
  71. data/lib/bundler/vendor/thor/shell/color.rb +108 -0
  72. data/lib/bundler/vendor/thor/shell/html.rb +121 -0
  73. data/lib/bundler/vendor/thor/task.rb +113 -0
  74. data/lib/bundler/vendor/thor/util.rb +229 -0
  75. data/lib/bundler/vendor/thor/version.rb +3 -0
  76. data/lib/bundler/vendored_thor.rb +7 -0
  77. data/lib/bundler/version.rb +6 -0
  78. data/lib/bundler/vlad.rb +11 -0
  79. data/man/bundle-config.ronn +90 -0
  80. data/man/bundle-exec.ronn +111 -0
  81. data/man/bundle-install.ronn +317 -0
  82. data/man/bundle-package.ronn +59 -0
  83. data/man/bundle-update.ronn +176 -0
  84. data/man/bundle.ronn +80 -0
  85. data/man/gemfile.5.ronn +284 -0
  86. data/man/index.txt +6 -0
  87. data/spec/bundler/gem_helper_spec.rb +143 -0
  88. data/spec/cache/gems_spec.rb +230 -0
  89. data/spec/cache/git_spec.rb +12 -0
  90. data/spec/cache/path_spec.rb +27 -0
  91. data/spec/cache/platform_spec.rb +57 -0
  92. data/spec/install/deploy_spec.rb +197 -0
  93. data/spec/install/deprecated_spec.rb +37 -0
  94. data/spec/install/gems/c_ext_spec.rb +48 -0
  95. data/spec/install/gems/env_spec.rb +107 -0
  96. data/spec/install/gems/flex_spec.rb +313 -0
  97. data/spec/install/gems/groups_spec.rb +259 -0
  98. data/spec/install/gems/packed_spec.rb +84 -0
  99. data/spec/install/gems/platform_spec.rb +192 -0
  100. data/spec/install/gems/resolving_spec.rb +72 -0
  101. data/spec/install/gems/simple_case_spec.rb +770 -0
  102. data/spec/install/gems/sudo_spec.rb +74 -0
  103. data/spec/install/gems/win32_spec.rb +26 -0
  104. data/spec/install/gemspec_spec.rb +125 -0
  105. data/spec/install/git_spec.rb +570 -0
  106. data/spec/install/invalid_spec.rb +35 -0
  107. data/spec/install/path_spec.rb +405 -0
  108. data/spec/install/upgrade_spec.rb +26 -0
  109. data/spec/lock/git_spec.rb +35 -0
  110. data/spec/lock/lockfile_spec.rb +739 -0
  111. data/spec/other/check_spec.rb +221 -0
  112. data/spec/other/config_spec.rb +40 -0
  113. data/spec/other/console_spec.rb +54 -0
  114. data/spec/other/exec_spec.rb +248 -0
  115. data/spec/other/ext_spec.rb +37 -0
  116. data/spec/other/help_spec.rb +39 -0
  117. data/spec/other/init_spec.rb +40 -0
  118. data/spec/other/newgem_spec.rb +46 -0
  119. data/spec/other/open_spec.rb +35 -0
  120. data/spec/other/show_spec.rb +82 -0
  121. data/spec/quality_spec.rb +62 -0
  122. data/spec/resolver/basic_spec.rb +20 -0
  123. data/spec/resolver/platform_spec.rb +82 -0
  124. data/spec/runtime/executable_spec.rb +110 -0
  125. data/spec/runtime/load_spec.rb +107 -0
  126. data/spec/runtime/platform_spec.rb +90 -0
  127. data/spec/runtime/require_spec.rb +231 -0
  128. data/spec/runtime/setup_spec.rb +730 -0
  129. data/spec/runtime/with_clean_env_spec.rb +15 -0
  130. data/spec/spec_helper.rb +92 -0
  131. data/spec/support/builders.rb +597 -0
  132. data/spec/support/helpers.rb +239 -0
  133. data/spec/support/indexes.rb +112 -0
  134. data/spec/support/matchers.rb +77 -0
  135. data/spec/support/path.rb +71 -0
  136. data/spec/support/platforms.rb +53 -0
  137. data/spec/support/ruby_ext.rb +20 -0
  138. data/spec/support/rubygems_ext.rb +37 -0
  139. data/spec/support/rubygems_hax/platform.rb +11 -0
  140. data/spec/support/sudo.rb +21 -0
  141. data/spec/update/gems_spec.rb +122 -0
  142. data/spec/update/git_spec.rb +196 -0
  143. data/spec/update/source_spec.rb +51 -0
  144. metadata +296 -0
@@ -0,0 +1,121 @@
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 = "<strong>"
11
+ # The end of an HTML bold sequence.
12
+ END_BOLD = "</strong>"
13
+
14
+ # Embed in a String to clear previous color selection.
15
+ CLEAR = "</span>"
16
+
17
+ # Set the terminal's foreground HTML color to black.
18
+ BLACK = '<span style="color: black;">'
19
+ # Set the terminal's foreground HTML color to red.
20
+ RED = '<span style="color: red;">'
21
+ # Set the terminal's foreground HTML color to green.
22
+ GREEN = '<span style="color: green;">'
23
+ # Set the terminal's foreground HTML color to yellow.
24
+ YELLOW = '<span style="color: yellow;">'
25
+ # Set the terminal's foreground HTML color to blue.
26
+ BLUE = '<span style="color: blue;">'
27
+ # Set the terminal's foreground HTML color to magenta.
28
+ MAGENTA = '<span style="color: magenta;">'
29
+ # Set the terminal's foreground HTML color to cyan.
30
+ CYAN = '<span style="color: cyan;">'
31
+ # Set the terminal's foreground HTML color to white.
32
+ WHITE = '<span style="color: white;">'
33
+
34
+ # Set the terminal's background HTML color to black.
35
+ ON_BLACK = '<span style="background-color: black">'
36
+ # Set the terminal's background HTML color to red.
37
+ ON_RED = '<span style="background-color: red">'
38
+ # Set the terminal's background HTML color to green.
39
+ ON_GREEN = '<span style="background-color: green">'
40
+ # Set the terminal's background HTML color to yellow.
41
+ ON_YELLOW = '<span style="background-color: yellow">'
42
+ # Set the terminal's background HTML color to blue.
43
+ ON_BLUE = '<span style="background-color: blue">'
44
+ # Set the terminal's background HTML color to magenta.
45
+ ON_MAGENTA = '<span style="background-color: magenta">'
46
+ # Set the terminal's background HTML color to cyan.
47
+ ON_CYAN = '<span style="background-color: cyan">'
48
+ # Set the terminal's background HTML color to white.
49
+ ON_WHITE = '<span style="background-color: white">'
50
+
51
+ # Set color by using a string or one of the defined constants. If a third
52
+ # option is set to true, it also adds bold to the string. This is based
53
+ # on Highline implementation and it automatically appends CLEAR to the end
54
+ # of the returned String.
55
+ #
56
+ def set_color(string, color, bold=false)
57
+ color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol)
58
+ bold, end_bold = bold ? [BOLD, END_BOLD] : ['', '']
59
+ "#{bold}#{color}#{string}#{CLEAR}#{end_bold}"
60
+ end
61
+
62
+ # Ask something to the user and receives a response.
63
+ #
64
+ # ==== Example
65
+ # ask("What is your name?")
66
+ #
67
+ # TODO: Implement #ask for Thor::Shell::HTML
68
+ def ask(statement, color=nil)
69
+ raise NotImplementedError, "Implement #ask for Thor::Shell::HTML"
70
+ end
71
+
72
+ protected
73
+
74
+ # Overwrite show_diff to show diff with colors if Diff::LCS is
75
+ # available.
76
+ #
77
+ def show_diff(destination, content) #:nodoc:
78
+ if diff_lcs_loaded? && ENV['THOR_DIFF'].nil? && ENV['RAILS_DIFF'].nil?
79
+ actual = File.binread(destination).to_s.split("\n")
80
+ content = content.to_s.split("\n")
81
+
82
+ Diff::LCS.sdiff(actual, content).each do |diff|
83
+ output_diff_line(diff)
84
+ end
85
+ else
86
+ super
87
+ end
88
+ end
89
+
90
+ def output_diff_line(diff) #:nodoc:
91
+ case diff.action
92
+ when '-'
93
+ say "- #{diff.old_element.chomp}", :red, true
94
+ when '+'
95
+ say "+ #{diff.new_element.chomp}", :green, true
96
+ when '!'
97
+ say "- #{diff.old_element.chomp}", :red, true
98
+ say "+ #{diff.new_element.chomp}", :green, true
99
+ else
100
+ say " #{diff.old_element.chomp}", nil, true
101
+ end
102
+ end
103
+
104
+ # Check if Diff::LCS is loaded. If it is, use it to create pretty output
105
+ # for diff.
106
+ #
107
+ def diff_lcs_loaded? #:nodoc:
108
+ return true if defined?(Diff::LCS)
109
+ return @diff_lcs_loaded unless @diff_lcs_loaded.nil?
110
+
111
+ @diff_lcs_loaded = begin
112
+ require 'diff/lcs'
113
+ true
114
+ rescue LoadError
115
+ false
116
+ end
117
+ end
118
+
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,113 @@
1
+ class Thor
2
+ class Task < Struct.new(:name, :description, :long_description, :usage, :options)
3
+ FILE_REGEXP = /^#{Regexp.escape(File.dirname(__FILE__))}/
4
+
5
+ def initialize(name, description, long_description, usage, options=nil)
6
+ super(name.to_s, description, long_description, usage, options || {})
7
+ end
8
+
9
+ def initialize_copy(other) #:nodoc:
10
+ super(other)
11
+ self.options = other.options.dup if other.options
12
+ end
13
+
14
+ def hidden?
15
+ false
16
+ end
17
+
18
+ # By default, a task invokes a method in the thor class. You can change this
19
+ # implementation to create custom tasks.
20
+ def run(instance, args=[])
21
+ public_method?(instance) ?
22
+ instance.send(name, *args) : instance.class.handle_no_task_error(name)
23
+ rescue ArgumentError => e
24
+ handle_argument_error?(instance, e, caller) ?
25
+ instance.class.handle_argument_error(self, e) : (raise e)
26
+ rescue NoMethodError => e
27
+ handle_no_method_error?(instance, e, caller) ?
28
+ instance.class.handle_no_task_error(name) : (raise e)
29
+ end
30
+
31
+ # Returns the formatted usage by injecting given required arguments
32
+ # and required options into the given usage.
33
+ def formatted_usage(klass, namespace = true, subcommand = false)
34
+ if namespace
35
+ namespace = klass.namespace
36
+ formatted = "#{namespace.gsub(/^(default)/,'')}:"
37
+ formatted.sub!(/.$/, ' ') if subcommand
38
+ end
39
+
40
+ formatted ||= ""
41
+
42
+ # Add usage with required arguments
43
+ formatted << if klass && !klass.arguments.empty?
44
+ usage.to_s.gsub(/^#{name}/) do |match|
45
+ match << " " << klass.arguments.map{ |a| a.usage }.compact.join(' ')
46
+ end
47
+ else
48
+ usage.to_s
49
+ end
50
+
51
+ # Add required options
52
+ formatted << " #{required_options}"
53
+
54
+ # Strip and go!
55
+ formatted.strip
56
+ end
57
+
58
+ protected
59
+
60
+ def not_debugging?(instance)
61
+ !(instance.class.respond_to?(:debugging) && instance.class.debugging)
62
+ end
63
+
64
+ def required_options
65
+ @required_options ||= options.map{ |_, o| o.usage if o.required? }.compact.sort.join(" ")
66
+ end
67
+
68
+ # Given a target, checks if this class name is a public method.
69
+ def public_method?(instance) #:nodoc:
70
+ !(instance.public_methods & [name.to_s, name.to_sym]).empty?
71
+ end
72
+
73
+ def sans_backtrace(backtrace, caller) #:nodoc:
74
+ saned = backtrace.reject { |frame| frame =~ FILE_REGEXP }
75
+ saned -= caller
76
+ end
77
+
78
+ def handle_argument_error?(instance, error, caller)
79
+ not_debugging?(instance) && error.message =~ /wrong number of arguments/ && begin
80
+ saned = sans_backtrace(error.backtrace, caller)
81
+ # Ruby 1.9 always include the called method in the backtrace
82
+ saned.empty? || (saned.size == 1 && RUBY_VERSION >= "1.9")
83
+ end
84
+ end
85
+
86
+ def handle_no_method_error?(instance, error, caller)
87
+ not_debugging?(instance) &&
88
+ error.message =~ /^undefined method `#{name}' for #{Regexp.escape(instance.to_s)}$/
89
+ end
90
+ end
91
+
92
+ # A task that is hidden in help messages but still invocable.
93
+ class HiddenTask < Task
94
+ def hidden?
95
+ true
96
+ end
97
+ end
98
+
99
+ # A dynamic task that handles method missing scenarios.
100
+ class DynamicTask < Task
101
+ def initialize(name, options=nil)
102
+ super(name.to_s, "A dynamically-generated task", name.to_s, name.to_s, options)
103
+ end
104
+
105
+ def run(instance, args=[])
106
+ if (instance.methods & [name.to_s, name.to_sym]).empty?
107
+ super
108
+ else
109
+ instance.class.handle_no_task_error(name)
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,229 @@
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
+ # Receives a namespace and search for it in the Thor::Base subclasses.
20
+ #
21
+ # ==== Parameters
22
+ # namespace<String>:: The namespace to search for.
23
+ #
24
+ def self.find_by_namespace(namespace)
25
+ namespace = "default#{namespace}" if namespace.empty? || namespace =~ /^:/
26
+ Thor::Base.subclasses.find { |klass| klass.namespace == namespace }
27
+ end
28
+
29
+ # Receives a constant and converts it to a Thor namespace. Since Thor tasks
30
+ # can be added to a sandbox, this method is also responsable for removing
31
+ # the sandbox namespace.
32
+ #
33
+ # This method should not be used in general because it's used to deal with
34
+ # older versions of Thor. On current versions, if you need to get the
35
+ # namespace from a class, just call namespace on it.
36
+ #
37
+ # ==== Parameters
38
+ # constant<Object>:: The constant to be converted to the thor path.
39
+ #
40
+ # ==== Returns
41
+ # String:: If we receive Foo::Bar::Baz it returns "foo:bar:baz"
42
+ #
43
+ def self.namespace_from_thor_class(constant)
44
+ constant = constant.to_s.gsub(/^Thor::Sandbox::/, "")
45
+ constant = snake_case(constant).squeeze(":")
46
+ constant
47
+ end
48
+
49
+ # Given the contents, evaluate it inside the sandbox and returns the
50
+ # namespaces defined in the sandbox.
51
+ #
52
+ # ==== Parameters
53
+ # contents<String>
54
+ #
55
+ # ==== Returns
56
+ # Array[Object]
57
+ #
58
+ def self.namespaces_in_content(contents, file=__FILE__)
59
+ old_constants = Thor::Base.subclasses.dup
60
+ Thor::Base.subclasses.clear
61
+
62
+ load_thorfile(file, contents)
63
+
64
+ new_constants = Thor::Base.subclasses.dup
65
+ Thor::Base.subclasses.replace(old_constants)
66
+
67
+ new_constants.map!{ |c| c.namespace }
68
+ new_constants.compact!
69
+ new_constants
70
+ end
71
+
72
+ # Returns the thor classes declared inside the given class.
73
+ #
74
+ def self.thor_classes_in(klass)
75
+ stringfied_constants = klass.constants.map { |c| c.to_s }
76
+ Thor::Base.subclasses.select do |subclass|
77
+ next unless subclass.name
78
+ stringfied_constants.include?(subclass.name.gsub("#{klass.name}::", ''))
79
+ end
80
+ end
81
+
82
+ # Receives a string and convert it to snake case. SnakeCase returns snake_case.
83
+ #
84
+ # ==== Parameters
85
+ # String
86
+ #
87
+ # ==== Returns
88
+ # String
89
+ #
90
+ def self.snake_case(str)
91
+ return str.downcase if str =~ /^[A-Z_]+$/
92
+ str.gsub(/\B[A-Z]/, '_\&').squeeze('_') =~ /_*(.*)/
93
+ return $+.downcase
94
+ end
95
+
96
+ # Receives a string and convert it to camel case. camel_case returns CamelCase.
97
+ #
98
+ # ==== Parameters
99
+ # String
100
+ #
101
+ # ==== Returns
102
+ # String
103
+ #
104
+ def self.camel_case(str)
105
+ return str if str !~ /_/ && str =~ /[A-Z]+.*/
106
+ str.split('_').map { |i| i.capitalize }.join
107
+ end
108
+
109
+ # Receives a namespace and tries to retrieve a Thor or Thor::Group class
110
+ # from it. It first searches for a class using the all the given namespace,
111
+ # if it's not found, removes the highest entry and searches for the class
112
+ # again. If found, returns the highest entry as the class name.
113
+ #
114
+ # ==== Examples
115
+ #
116
+ # class Foo::Bar < Thor
117
+ # def baz
118
+ # end
119
+ # end
120
+ #
121
+ # class Baz::Foo < Thor::Group
122
+ # end
123
+ #
124
+ # Thor::Util.namespace_to_thor_class("foo:bar") #=> Foo::Bar, nil # will invoke default task
125
+ # Thor::Util.namespace_to_thor_class("baz:foo") #=> Baz::Foo, nil
126
+ # Thor::Util.namespace_to_thor_class("foo:bar:baz") #=> Foo::Bar, "baz"
127
+ #
128
+ # ==== Parameters
129
+ # namespace<String>
130
+ #
131
+ def self.find_class_and_task_by_namespace(namespace, fallback = true)
132
+ if namespace.include?(?:) # look for a namespaced task
133
+ pieces = namespace.split(":")
134
+ task = pieces.pop
135
+ klass = Thor::Util.find_by_namespace(pieces.join(":"))
136
+ end
137
+ unless klass # look for a Thor::Group with the right name
138
+ klass, task = Thor::Util.find_by_namespace(namespace), nil
139
+ end
140
+ if !klass && fallback # try a task in the default namespace
141
+ task = namespace
142
+ klass = Thor::Util.find_by_namespace('')
143
+ end
144
+ return klass, task
145
+ end
146
+
147
+ # Receives a path and load the thor file in the path. The file is evaluated
148
+ # inside the sandbox to avoid namespacing conflicts.
149
+ #
150
+ def self.load_thorfile(path, content=nil, debug=false)
151
+ content ||= File.binread(path)
152
+
153
+ begin
154
+ Thor::Sandbox.class_eval(content, path)
155
+ rescue Exception => e
156
+ $stderr.puts "WARNING: unable to load thorfile #{path.inspect}: #{e.message}"
157
+ if debug
158
+ $stderr.puts *e.backtrace
159
+ else
160
+ $stderr.puts e.backtrace.first
161
+ end
162
+ end
163
+ end
164
+
165
+ def self.user_home
166
+ @@user_home ||= if ENV["HOME"]
167
+ ENV["HOME"]
168
+ elsif ENV["USERPROFILE"]
169
+ ENV["USERPROFILE"]
170
+ elsif ENV["HOMEDRIVE"] && ENV["HOMEPATH"]
171
+ File.join(ENV["HOMEDRIVE"], ENV["HOMEPATH"])
172
+ elsif ENV["APPDATA"]
173
+ ENV["APPDATA"]
174
+ else
175
+ begin
176
+ File.expand_path("~")
177
+ rescue
178
+ if File::ALT_SEPARATOR
179
+ "C:/"
180
+ else
181
+ "/"
182
+ end
183
+ end
184
+ end
185
+ end
186
+
187
+ # Returns the root where thor files are located, dependending on the OS.
188
+ #
189
+ def self.thor_root
190
+ File.join(user_home, ".thor").gsub(/\\/, '/')
191
+ end
192
+
193
+ # Returns the files in the thor root. On Windows thor_root will be something
194
+ # like this:
195
+ #
196
+ # C:\Documents and Settings\james\.thor
197
+ #
198
+ # If we don't #gsub the \ character, Dir.glob will fail.
199
+ #
200
+ def self.thor_root_glob
201
+ files = Dir["#{thor_root}/*"]
202
+
203
+ files.map! do |file|
204
+ File.directory?(file) ? File.join(file, "main.thor") : file
205
+ end
206
+ end
207
+
208
+ # Where to look for Thor files.
209
+ #
210
+ def self.globs_for(path)
211
+ ["#{path}/Thorfile", "#{path}/*.thor", "#{path}/tasks/*.thor", "#{path}/lib/tasks/*.thor"]
212
+ end
213
+
214
+ # Return the path to the ruby interpreter taking into account multiple
215
+ # installations and windows extensions.
216
+ #
217
+ def self.ruby_command
218
+ @ruby_command ||= begin
219
+ ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
220
+ ruby << RbConfig::CONFIG['EXEEXT']
221
+
222
+ # escape string in case path to ruby executable contain spaces.
223
+ ruby.sub!(/.*\s.*/m, '"\&"')
224
+ ruby
225
+ end
226
+ end
227
+
228
+ end
229
+ end