diff options
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/commands/console.rb | 13 | ||||
-rw-r--r-- | railties/lib/rails/commands/server.rb | 5 | ||||
-rw-r--r-- | railties/lib/rails/paths.rb | 31 | ||||
-rw-r--r-- | railties/lib/rails/source_annotation_extractor.rb | 2 |
4 files changed, 49 insertions, 2 deletions
diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb index 86376ac7e6..d7c9e820dc 100644 --- a/railties/lib/rails/commands/console.rb +++ b/railties/lib/rails/commands/console.rb @@ -24,6 +24,9 @@ module Rails OptionParser.new do |opt| opt.banner = "Usage: console [environment] [options]" opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |v| options[:sandbox] = v } + opt.on("-e", "--environment=name", String, + "Specifies the environment to run this console under (test/development/production).", + "Default: development") { |v| options[:environment] = v.strip } opt.on("--debugger", 'Enable ruby-debugging for the console.') { |v| options[:debugger] = v } opt.parse!(arguments) end @@ -36,6 +39,14 @@ module Rails options[:sandbox] end + def environment? + options[:environment] + end + + def set_environment! + Rails.env = options[:environment] + end + def debugger? options[:debugger] end @@ -45,6 +56,8 @@ module Rails require_debugger if debugger? + set_environment! if environment? + if sandbox? puts "Loading #{Rails.env} environment in sandbox (Rails #{Rails.version})" puts "Any modifications you make will be rolled back on exit" diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index a608693ca4..721a47a974 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -32,6 +32,11 @@ module Rails opt_parser.parse! args + # Handle's environment like RAILS_ENV=production passed in directly + if index = args.index {|arg| arg.include?("RAILS_ENV")} + options[:environment] ||= args.delete_at(index).split('=').last + end + options[:server] = args.shift options end diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index b37421c09c..4ac3d88dc2 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -157,7 +157,25 @@ module Rails path = File.expand_path(p, @root.path) if @glob - result.concat Dir[File.join(path, @glob)].sort + if File.directory? path + result.concat expand_dir(path, @glob) + else + # FIXME: I think we can remove this branch, but I'm not sure. + # Say the filesystem has this file: + # + # /tmp/foobar + # + # and someone adds this path: + # + # /tmp/foo + # + # with a glob of "*", then this function will return + # + # /tmp/foobar + # + # We need to figure out if that is desired behavior. + result.concat expand_file(path, @glob) + end else result << path end @@ -177,6 +195,17 @@ module Rails end alias to_a expanded + + private + def expand_file(path, glob) + Dir[File.join(path, glob)].sort + end + + def expand_dir(path, glob) + Dir.chdir(path) do + Dir.glob(@glob).map { |file| File.join path, file }.sort + end + end end end end diff --git a/railties/lib/rails/source_annotation_extractor.rb b/railties/lib/rails/source_annotation_extractor.rb index 9bfc2b16ab..4cd60fdc39 100644 --- a/railties/lib/rails/source_annotation_extractor.rb +++ b/railties/lib/rails/source_annotation_extractor.rb @@ -22,7 +22,7 @@ class SourceAnnotationExtractor # If +options+ has a flag <tt>:tag</tt> the tag is shown as in the example above. # Otherwise the string contains just line and text. def to_s(options={}) - s = "[#{line.to_s.rjust(options[:indent])}]" + s = "[#{line.to_s.rjust(options[:indent])}] " s << "[#{tag}] " if options[:tag] s << text end |