Skip to content

Commit

Permalink
Update vendored thor and ensure that content is completely modified b…
Browse files Browse the repository at this point in the history
…efore checking file collisions.

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information
josevalim authored and jeremy committed Dec 2, 2009
1 parent 74be700 commit 28657e4
Show file tree
Hide file tree
Showing 33 changed files with 38 additions and 36 deletions.
2 changes: 1 addition & 1 deletion railties/lib/rails/generators.rb
Expand Up @@ -9,7 +9,7 @@
require 'active_support/core_ext/string/inflections'

# TODO: Do not always push on vendored thor
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/vendor/thor-0.12.0/lib")
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/vendor/thor-0.12.1/lib")
require 'rails/generators/base'
require 'rails/generators/named_base'

Expand Down
6 changes: 3 additions & 3 deletions railties/lib/rails/generators/rails/app/app_generator.rb
Expand Up @@ -123,10 +123,10 @@ def create_prototype_files
end

def create_script_files
directory "script" do |file|
prepend_file file, "#{shebang}\n", :verbose => false
chmod file, 0755, :verbose => false
directory "script" do |content|
"#{shebang}\n" + content
end
chmod "script", 0755, :verbose => false
end

def create_test_files
Expand Down
3 changes: 0 additions & 3 deletions railties/lib/rails/vendor/thor-0.12.0/lib/thor/version.rb

This file was deleted.

Expand Up @@ -17,7 +17,7 @@

* thor help now show information about any class/task. All those calls are
possible:

thor help describe
thor help describe:amazing

Expand Down Expand Up @@ -47,7 +47,7 @@
are in the 'standard' group. Running 'thor -T' will only show the standard
tasks - adding --all will show all tasks. You can also filter on a specific
group using the --group option: thor -T --group advanced

== 0.9.6, released 2008-09-13

* Generic improvements
Expand Down
Expand Up @@ -7,7 +7,7 @@ Example:

class App < Thor # [1]
map "-L" => :list # [2]

desc "install APP_NAME", "install one of the available apps" # [3]
method_options :force => :boolean, :alias => :string # [4]
def install(name)
Expand All @@ -17,7 +17,7 @@ Example:
end
# other code
end

desc "list [SEARCH]", "list all of the available apps, limited by SEARCH"
def list(search="")
# list everything
Expand Down Expand Up @@ -126,13 +126,13 @@ invoked only once. For example:
invoke :two
invoke :three
end

desc "two", "Prints 2, 3"
def two
puts 2
invoke :three
end

desc "three", "Prints 3"
def three
puts 3
Expand All @@ -155,15 +155,15 @@ Thor::Group as this:

class Counter < Thor::Group
desc "Prints 1, 2, 3"

def one
puts 1
end

def two
puts 2
end

def three
puts 3
end
Expand All @@ -184,15 +184,15 @@ Besides, Thor::Group can parse arguments and options as Thor tasks:
# number will be available as attr_accessor
argument :number, :type => :numeric, :desc => "The number to start counting"
desc "Prints the 'number' given upto 'number+2'"

def one
puts number + 0
end

def two
puts number + 1
end

def three
puts number + 2
end
Expand Down
Expand Up @@ -56,7 +56,7 @@ class Default < Thor
s.test_files.exclude 'spec/sandbox/**/*'
end

Jeweler::RubyforgeTasks.new
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end
Expand Down
Expand Up @@ -114,7 +114,7 @@ def source_paths
@source_paths ||= self.class.source_paths_for_search
end

# Receives a file or directory and search for it in the source paths.
# Receives a file or directory and search for it in the source paths.
#
def find_in_source_paths(file)
relative_root = relative_to_original_destination_root(destination_root, false)
Expand Down Expand Up @@ -222,7 +222,7 @@ def run_ruby_script(command, config={})
run "#{command}", config.merge(:with => Thor::Util.ruby_command)
end

# Run a thor command. A hash of options can be given and it's converted to
# Run a thor command. A hash of options can be given and it's converted to
# switches.
#
# ==== Parameters
Expand Down
Expand Up @@ -79,11 +79,9 @@ def execute!
next if dirname == given_destination
base.empty_directory(dirname, config)
when /\.tt$/
destination = base.template(file_source, file_destination[0..-4], config)
@block.call(destination) if @block
destination = base.template(file_source, file_destination[0..-4], config, &@block)
else
destination = base.copy_file(file_source, file_destination, config)
@block.call(destination) if @block
destination = base.copy_file(file_source, file_destination, config, &@block)
end
end
end
Expand Down
Expand Up @@ -18,12 +18,14 @@ module Actions
#
# copy_file "doc/README"
#
def copy_file(source, destination=nil, config={})
def copy_file(source, destination=nil, config={}, &block)
destination ||= source
source = File.expand_path(find_in_source_paths(source.to_s))

create_file destination, nil, config do
File.read(source)
content = File.read(source)
content = block.call(content) if block
content
end
end

Expand Down Expand Up @@ -72,13 +74,15 @@ def get(source, destination=nil, config={}, &block)
#
# template "doc/README"
#
def template(source, destination=nil, config={})
def template(source, destination=nil, config={}, &block)
destination ||= source
source = File.expand_path(find_in_source_paths(source.to_s))
context = instance_eval('binding')

create_file destination, nil, config do
ERB.new(::File.read(source), nil, '-').result(context)
content = ERB.new(::File.read(source), nil, '-').result(context)
content = block.call(content) if block
content
end
end

Expand Down
Expand Up @@ -11,7 +11,7 @@ module Actions
# data<String>:: Data to add to the file. Can be given as a block.
# config<Hash>:: give :verbose => false to not log the status and the flag
# for injection (:after or :before).
#
#
# ==== Examples
#
# inject_into_file "config/environment.rb", "config.gem :thor", :after => "Rails::Initializer.run do |config|\n"
Expand Down
Expand Up @@ -65,7 +65,7 @@ def method_missing(method, *args, &block)
else
self[$1] == args.first
end
else
else
self[method]
end
end
Expand Down
Expand Up @@ -132,7 +132,7 @@ def invoke_from_option(*names, &block)

names.each do |name|
unless class_options.key?(name)
raise ArgumentError, "You have to define the option #{name.inspect} " <<
raise ArgumentError, "You have to define the option #{name.inspect} " <<
"before setting invoke_from_option."
end

Expand Down
Expand Up @@ -36,7 +36,7 @@ def initialize(name, description=nil, required=nil, type=nil, default=nil, banne
# string (--foo=value) or booleans (just --foo).
#
# By default all options are optional, unless :required is given.
#
#
def self.parse(key, value)
if key.is_a?(Array)
name, *aliases = key
Expand Down
Expand Up @@ -36,7 +36,7 @@ def method_missing(meth, *args)
def install(name)
initialize_thorfiles

# If a directory name is provided as the argument, look for a 'main.thor'
# If a directory name is provided as the argument, look for a 'main.thor'
# task in said directory.
begin
if File.directory?(File.expand_path(name))
Expand Down
Expand Up @@ -143,7 +143,7 @@ def file_collision(destination)
answer = ask %[Overwrite #{destination}? (enter "h" for help) #{options}]

case answer
when is?(:yes), is?(:force)
when is?(:yes), is?(:force), ""
return true
when is?(:no), is?(:skip)
return false
Expand Down
3 changes: 3 additions & 0 deletions railties/lib/rails/vendor/thor-0.12.1/lib/thor/version.rb
@@ -0,0 +1,3 @@
class Thor
VERSION = "0.12.1".freeze
end

0 comments on commit 28657e4

Please sign in to comment.