diff options
author | José Valim <jose.valim@gmail.com> | 2009-07-15 20:16:37 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-07-15 20:16:37 +0200 |
commit | b4ef958de6b16294094de28d00ba25fe2f48accc (patch) | |
tree | 89ccd25109c5095125faeab8d5fcc318fa94ceb2 /railties/lib | |
parent | baa4781ac7174e527c2471b4c86ea51c0f65cf6b (diff) | |
download | rails-b4ef958de6b16294094de28d00ba25fe2f48accc.tar.gz rails-b4ef958de6b16294094de28d00ba25fe2f48accc.tar.bz2 rails-b4ef958de6b16294094de28d00ba25fe2f48accc.zip |
Change false to :verbose => false as in new Thor version.
Diffstat (limited to 'railties/lib')
13 files changed, 117 insertions, 128 deletions
diff --git a/railties/lib/generators/actions.rb b/railties/lib/generators/actions.rb index 34c78aaad8..81db0b7c37 100644 --- a/railties/lib/generators/actions.rb +++ b/railties/lib/generators/actions.rb @@ -16,12 +16,13 @@ module Rails # # apply "recipes/jquery.rb" # - def apply(path, log_status=true) + def apply(path) path = find_in_source_paths(path) unless path =~ /^http\:\/\// - log :apply, path, log_status + log :apply, path + shell.padding += 1 instance_eval(open(path).read) - log :applied, path, log_status + shell.padding -= 1 end # Install a plugin. You must provide either a Subversion url or Git url. @@ -38,11 +39,11 @@ module Rails if options[:git] && options[:submodule] in_root do - run "git submodule add #{options[:git]} vendor/plugins/#{name}", false + run "git submodule add #{options[:git]} vendor/plugins/#{name}", :verbose => false end elsif options[:git] || options[:svn] in_root do - run_ruby_script "script/plugin install #{options[:svn] || options[:git]}", false + run_ruby_script "script/plugin install #{options[:svn] || options[:git]}", :verbose => false end else log "! no git or svn provided for #{name}. Skipping..." @@ -57,7 +58,7 @@ module Rails # gem "rspec", :env => :test # gem "technoweenie-restful-authentication", :lib => "restful-authentication", :source => "http://gems.github.com/" # - def gem(name, options = {}) + def gem(name, options={}) log :gem, name env = options.delete(:env) @@ -82,10 +83,10 @@ module Rails in_root do if options[:env].nil? - inject_into_file 'config/environment.rb', "\n #{data}", { :after => sentinel }, false + inject_into_file 'config/environment.rb', "\n #{data}", :after => sentinel, :verbose => false else Array.wrap(options[:env]).each do|env| - append_file "config/environments/#{env}.rb", "\n#{data}", false + append_file "config/environments/#{env}.rb", "\n#{data}", :verbose => false end end end @@ -99,7 +100,7 @@ module Rails # git :add => "this.file that.rb" # git :add => "onefile.rb", :rm => "badfile.cxx" # - def git(command = {}) + def git(command={}) in_root do if command.is_a?(Symbol) run "git #{command}" @@ -125,7 +126,7 @@ module Rails # def vendor(filename, data=nil, &block) log :vendor, filename - create_file("vendor/#{filename}", data, false, &block) + create_file("vendor/#{filename}", data, :verbose => false, &block) end # Create a new file in the lib/ directory. Code can be specified @@ -141,7 +142,7 @@ module Rails # def lib(filename, data=nil, &block) log :lib, filename - create_file("lib/#{filename}", data, false, &block) + create_file("lib/#{filename}", data, :verbose => false, &block) end # Create a new Rakefile with the provided code (either in a block or a string). @@ -164,7 +165,7 @@ module Rails # def rakefile(filename, data=nil, &block) log :rakefile, filename - create_file("lib/tasks/#{filename}", data, false, &block) + create_file("lib/tasks/#{filename}", data, :verbose => false, &block) end # Create a new initializer with the provided code (either in a block or a string). @@ -185,7 +186,7 @@ module Rails # def initializer(filename, data=nil, &block) log :initializer, filename - create_file("config/initializers/#{filename}", data, false, &block) + create_file("config/initializers/#{filename}", data, :verbose => false, &block) end # Generate something using a generator from Rails or a plugin. @@ -200,7 +201,7 @@ module Rails log :generate, what argument = args.map {|arg| arg.to_s }.flatten.join(" ") - in_root { run_ruby_script("script/generate #{what} #{argument}", false) } + in_root { run_ruby_script("script/generate #{what} #{argument}", :verbose => false) } end # Runs the supplied rake task @@ -215,7 +216,7 @@ module Rails log :rake, command env = options[:env] || 'development' sudo = options[:sudo] && RUBY_PLATFORM !~ /mswin|mingw/ ? 'sudo ' : '' - in_root { run("#{sudo}#{extify(:rake)} #{command} RAILS_ENV=#{env}", false) } + in_root { run("#{sudo}#{extify(:rake)} #{command} RAILS_ENV=#{env}", :verbose => false) } end # Just run the capify command in root @@ -226,7 +227,7 @@ module Rails # def capify! log :capify, "" - in_root { run("#{extify(:capify)} .", false) } + in_root { run("#{extify(:capify)} .", :verbose => false) } end # Add Rails to /vendor/rails @@ -237,7 +238,7 @@ module Rails # def freeze!(args = {}) log :vendor, "rails" - in_root { run("#{extify(:rake)} rails:freeze:edge", false) } + in_root { run("#{extify(:rake)} rails:freeze:edge", :verbose => false) } end # Make an entry in Rails routing file conifg/routes.rb @@ -251,7 +252,7 @@ module Rails sentinel = "ActionController::Routing::Routes.draw do |map|" in_root do - inject_into_file 'config/routes.rb', "\n #{routing_code}\n", { :after => sentinel }, false + inject_into_file 'config/routes.rb', "\n #{routing_code}\n", { :after => sentinel, :verbose => false } end end diff --git a/railties/lib/generators/migration.rb b/railties/lib/generators/migration.rb index 7014e6deda..0a9151ecdf 100644 --- a/railties/lib/generators/migration.rb +++ b/railties/lib/generators/migration.rb @@ -22,7 +22,7 @@ module Rails # # migration_template "migration.rb", "db/migrate/add_foo_to_bar.rb" # - def migration_template(source, destination=nil, log_status=true) + def migration_template(source, destination=nil, config={}) destination = File.expand_path(destination || source, self.destination_root) migration_dir = File.dirname(destination) @@ -37,7 +37,7 @@ module Rails destination = File.join(migration_dir, "#{@migration_number}_#{@migration_file_name}.rb") end - template(source, destination, log_status) + template(source, destination, config) end protected diff --git a/railties/lib/generators/rails/app/app_generator.rb b/railties/lib/generators/rails/app/app_generator.rb index 88a52c60b0..eaeb49903a 100644 --- a/railties/lib/generators/rails/app/app_generator.rb +++ b/railties/lib/generators/rails/app/app_generator.rb @@ -100,13 +100,13 @@ module Rails::Generators inside "log" do %w( server production development test ).each do |file| create_file "#{file}.log" - chmod "#{file}.log", 0666, false + chmod "#{file}.log", 0666, :verbose => false end end end def create_public_files - directory "public", "public", false # Non-recursive. Do small steps, so anyone can overwrite it. + directory "public", "public", :recursive => false # Do small steps, so anyone can overwrite it. end def create_dispatch_files @@ -114,13 +114,13 @@ module Rails::Generators copy_file "dispatchers/config.ru", "config.ru" template "dispatchers/dispatch.rb", "public/dispatch.rb" - chmod "public/dispatch.rb", 0755, false + chmod "public/dispatch.rb", 0755, :verbose => false template "dispatchers/dispatch.rb", "public/dispatch.cgi" - chmod "public/dispatch.cgi", 0755, false + chmod "public/dispatch.cgi", 0755, :verbose => false template "dispatchers/dispatch.fcgi", "public/dispatch.fcgi" - chmod "public/dispatch.fcgi", 0755, false + chmod "public/dispatch.fcgi", 0755, :verbose => false end def create_public_image_files @@ -138,7 +138,7 @@ module Rails::Generators def create_script_files directory "script" - chmod "script", 0755, false + chmod "script", 0755, :verbose => false end def create_test_files diff --git a/railties/lib/generators/rails/plugin/plugin_generator.rb b/railties/lib/generators/rails/plugin/plugin_generator.rb index a7417f28c2..dcdc125867 100644 --- a/railties/lib/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/generators/rails/plugin/plugin_generator.rb @@ -8,11 +8,11 @@ module Rails check_class_collision def create_root_files - directory '.', plugin_dir, false # non-recursive + directory '.', plugin_dir, :recursive => false end def create_lib_files - directory 'lib', plugin_dir('lib'), false # non-recursive + directory 'lib', plugin_dir('lib'), :recursive => false end def create_tasks_files diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions.rb index 83d082382c..939339088a 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions.rb @@ -164,8 +164,8 @@ class Thor # Same as inside, but log status and use padding. # - def inside_with_padding(dir='', log_status=true, &block) - say_status :inside, dir, log_status + def inside_with_padding(dir='', config={}, &block) + say_status :inside, dir, config.fetch(:verbose, true) shell.padding += 1 inside(dir, &block) shell.padding -= 1 @@ -182,17 +182,16 @@ class Thor # ==== Parameters # mode<Integer>:: the file mode # path<String>:: the name of the file to change mode - # log_status<Boolean>:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config<Hash>:: give :verbose => false to not log the status. # # ==== Example # # chmod "script/*", 0755 # - def chmod(path, mode, log_status=true) + def chmod(path, mode, config={}) return unless behavior == :invoke path = File.expand_path(path, destination_root) - say_status :chmod, relative_to_original_destination_root(path), log_status + say_status :chmod, relative_to_original_destination_root(path), config.fetch(:verbose, true) FileUtils.chmod_R(mode, path) unless options[:pretend] end @@ -200,8 +199,7 @@ class Thor # # ==== Parameters # command<String>:: the command to be executed. - # log_status<Boolean>:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config<Hash>:: give :verbose => false to not log the status. # # ==== Example # @@ -209,9 +207,10 @@ class Thor # run('ln -s ~/edge rails') # end # - def run(command, log_status=true) + def run(command, config={}) return unless behavior == :invoke - say_status :run, "\"#{command}\" from #{relative_to_original_destination_root(destination_root, false)}", log_status + description = "#{command.inspect} from #{relative_to_original_destination_root(destination_root, false)}" + say_status :run, description, config.fetch(:verbose, true) `#{command}` unless options[:pretend] end @@ -219,12 +218,11 @@ class Thor # # ==== Parameters # command<String>:: the command to be executed. - # log_status<Boolean>:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config<Hash>:: give :verbose => false to not log the status. # - def run_ruby_script(command, log_status=true) + def run_ruby_script(command, config={}) return unless behavior == :invoke - say_status File.basename(Thor::Util.ruby_command), command, log_status + say_status File.basename(Thor::Util.ruby_command), command, config.fetch(:verbose, true) `#{Thor::Util.ruby_command} #{command}` unless options[:pretend] end @@ -234,9 +232,8 @@ class Thor # ==== Parameters # task<String>:: the task to be invoked # args<Array>:: arguments to the task - # options<Hash>:: a hash with options used on invocation - # log_status<Boolean>:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # options<Hash>:: give :verbose => false to not log the status. Other options + # are given as parameter to Thor. # # ==== Examples # @@ -247,35 +244,33 @@ class Thor # #=> thor list --all --substring=rails # def thor(task, *args) - log_status = args.last.is_a?(Symbol) || [true, false].include?(args.last) ? args.pop : true - options = args.last.is_a?(Hash) ? args.pop : {} + config = args.last.is_a?(Hash) ? args.pop : {} + verbose = config.key?(:verbose) ? config.delete(:verbose) : true args.unshift task - args.push Thor::Options.to_switches(options) + args.push Thor::Options.to_switches(config) command = args.join(' ').strip - say_status :thor, command, log_status - run "thor #{command}", false + say_status :thor, command, verbose + run "thor #{command}", :verbose => false end # Removes a file at the given location. # # ==== Parameters # path<String>:: path of the file to be changed - # log_status<Boolean>:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config<Hash>:: give :verbose => false to not log the status. # # ==== Example # # remove_file 'README' # remove_file 'app/controllers/application_controller.rb' # - def remove_file(path, log_status=true) + def remove_file(path, config={}) return unless behavior == :invoke path = File.expand_path(path, destination_root) - color = log_status.is_a?(Symbol) ? log_status : :red - say_status :remove, relative_to_original_destination_root(path), log_status + say_status :remove, relative_to_original_destination_root(path), config.fetch(:verbose, true) ::FileUtils.rm_rf(path) if !options[:pretend] && File.exists?(path) end @@ -285,8 +280,7 @@ class Thor # path<String>:: path of the file to be changed # flag<Regexp|String>:: the regexp or string to be replaced # replacement<String>:: the replacement, can be also given as a block - # log_status<Boolean>:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config<Hash>:: give :verbose => false to not log the status. # # ==== Example # @@ -298,10 +292,10 @@ class Thor # def gsub_file(path, flag, *args, &block) return unless behavior == :invoke - log_status = args.last.is_a?(Symbol) || [ true, false ].include?(args.last) ? args.pop : true + config = args.last.is_a?(Hash) ? args.pop : {} path = File.expand_path(path, destination_root) - say_status :gsub, relative_to_original_destination_root(path), log_status + say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true) unless options[:pretend] content = File.read(path) @@ -315,17 +309,16 @@ class Thor # ==== Parameters # path<String>:: path of the file to be changed # data<String>:: the data to append to the file, can be also given as a block. - # log_status<Boolean>:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config<Hash>:: give :verbose => false to not log the status. # # ==== Example # # append_file 'config/environments/test.rb', 'config.gem "rspec"' # - def append_file(path, data=nil, log_status=true, &block) + def append_file(path, data=nil, config={}, &block) return unless behavior == :invoke path = File.expand_path(path, destination_root) - say_status :append, relative_to_original_destination_root(path), log_status + say_status :append, relative_to_original_destination_root(path), config.fetch(:verbose, true) File.open(path, 'ab') { |file| file.write(data || block.call) } unless options[:pretend] end @@ -334,17 +327,16 @@ class Thor # ==== Parameters # path<String>:: path of the file to be changed # data<String>:: the data to prepend to the file, can be also given as a block. - # log_status<Boolean>:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config<Hash>:: give :verbose => false to not log the status. # # ==== Example # # prepend_file 'config/environments/test.rb', 'config.gem "rspec"' # - def prepend_file(path, data=nil, log_status=true, &block) + def prepend_file(path, data=nil, config={}, &block) return unless behavior == :invoke path = File.expand_path(path, destination_root) - say_status :prepend, relative_to_original_destination_root(path), log_status + say_status :prepend, relative_to_original_destination_root(path), config.fetch(:verbose, true) unless options[:pretend] content = data || block.call diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/copy_file.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/copy_file.rb index b9d2e9e0a7..bfbc38a367 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/copy_file.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/copy_file.rb @@ -7,9 +7,9 @@ class Thor # the destination is not given it's assumed to be equal to the source. # # ==== Parameters - # source<String>:: the relative path to the source root - # destination<String>:: the relative path to the destination root - # log_status<Boolean>:: if false, does not log the status. True by default. + # source<String>:: the relative path to the source root. + # destination<String>:: the relative path to the destination root. + # config<Hash>:: give :verbose => false to not log the status. # # ==== Examples # @@ -17,8 +17,8 @@ class Thor # # copy_file "doc/README" # - def copy_file(source, destination=nil, log_status=true) - action CopyFile.new(self, source, destination || source, log_status) + def copy_file(source, destination=nil, config={}) + action CopyFile.new(self, source, destination || source, config) end class CopyFile < Templater #:nodoc: diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/create_file.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/create_file.rb index 2f3732247e..72bf34c0a3 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/create_file.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/create_file.rb @@ -9,7 +9,7 @@ class Thor # ==== Parameters # destination<String>:: the relative path to the destination root. # data<String|NilClass>:: the data to append to the file. - # log_status<Boolean>:: if false, does not log the status. True by default. + # config<Hash>:: give :verbose => false to not log the status. # # ==== Examples # @@ -20,8 +20,8 @@ class Thor # # create_file "config/apach.conf", "your apache config" # - def create_file(destination, data=nil, log_status=true, &block) - action CreateFile.new(self, destination, block || data.to_s, log_status) + def create_file(destination, data=nil, config={}, &block) + action CreateFile.new(self, destination, block || data.to_s, config) end alias :add_file :create_file @@ -31,8 +31,8 @@ class Thor class CreateFile < Templater #:nodoc: attr_reader :data - def initialize(base, destination, data, log_status) - super(base, nil, destination, log_status) + def initialize(base, destination, data, config={}) + super(base, nil, destination, config) @data = data end diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/directory.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/directory.rb index 134f13d1b7..2c6d2bc59b 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/directory.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/directory.rb @@ -30,30 +30,27 @@ class Thor # blog.rb # # ==== Parameters - # source<String>:: the relative path to the source root - # destination<String>:: the relative path to the destination root - # recursive<Boolean>:: if the directory must be copied recursively, true by default - # log_status<Boolean>:: if false, does not log the status. True by default. + # source<String>:: the relative path to the source root. + # destination<String>:: the relative path to the destination root. + # config<Hash>:: give :verbose => false to not log the status. + # If :recursive => false, does not look for paths recursively. # # ==== Examples # # directory "doc" - # directory "doc", "docs", false + # directory "doc", "docs", :recursive => false # - def directory(source, destination=nil, recursive=true, log_status=true) - action Directory.new(self, source, destination || source, recursive, log_status) + def directory(source, destination=nil, config={}) + action Directory.new(self, source, destination || source, config) end class Directory < Templater #:nodoc: - attr_reader :recursive - - def initialize(base, source, destination=nil, recursive=true, log_status=true) - @recursive = recursive - super(base, source, destination, log_status) + def initialize(base, source, destination=nil, config={}) + super(base, source, destination, { :recursive => true }.merge(config)) end def invoke! - base.empty_directory given_destination, @log_status + base.empty_directory given_destination, config execute! end @@ -64,7 +61,7 @@ class Thor protected def execute! - lookup = recursive ? File.join(source, '**') : source + lookup = config[:recursive] ? File.join(source, '**') : source lookup = File.join(lookup, '{*,.[a-z]*}') Dir[lookup].each do |file_source| @@ -73,11 +70,11 @@ class Thor case file_source when /\.empty_directory$/ - base.empty_directory(File.dirname(file_destination), @log_status) + base.empty_directory(File.dirname(file_destination), config) when /\.tt$/ - base.template(file_source, file_destination[0..-4], @log_status) + base.template(file_source, file_destination[0..-4], config) else - base.copy_file(file_source, file_destination, @log_status) + base.copy_file(file_source, file_destination, config) end end end diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/empty_directory.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/empty_directory.rb index 3f29d52362..04f9817212 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/empty_directory.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/empty_directory.rb @@ -6,21 +6,21 @@ class Thor # Creates an empty directory. # # ==== Parameters - # destination<String>:: the relative path to the destination root - # log_status<Boolean>:: if false, does not log the status. True by default. + # destination<String>:: the relative path to the destination root. + # config<Hash>:: give :verbose => false to not log the status. # # ==== Examples # # empty_directory "doc" # - def empty_directory(destination, log_status=true) - action EmptyDirectory.new(self, nil, destination, log_status) + def empty_directory(destination, config={}) + action EmptyDirectory.new(self, nil, destination, config) end class EmptyDirectory < Templater #:nodoc: def invoke! - invoke_with_options!(base.options) do + invoke_with_options!(base.options.merge(config)) do ::FileUtils.mkdir_p(destination) end end diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/get.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/get.rb index a0d12b8370..bd8deb8194 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/get.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/get.rb @@ -9,9 +9,9 @@ class Thor # the url is yielded and used as location. # # ==== Parameters - # source<String>:: the address of the given content - # destination<String>:: the relative path to the destination root - # log_status<Boolean>:: if false, does not log the status. True by default. + # source<String>:: the address of the given content. + # destination<String>:: the relative path to the destination root. + # config<Hash>:: give :verbose => false to not log the status. # # ==== Examples # @@ -21,8 +21,8 @@ class Thor # content.split("\n").first # end # - def get(source, destination=nil, log_status=true, &block) - action Get.new(self, source, block || destination, log_status) + def get(source, destination=nil, config={}, &block) + action Get.new(self, source, block || destination, config) end class Get < Templater #:nodoc: diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/inject_into_file.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/inject_into_file.rb index c91bd96098..6bd0100a12 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/inject_into_file.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/inject_into_file.rb @@ -9,9 +9,8 @@ class Thor # ==== Parameters # destination<String>:: Relative path to the destination root # data<String>:: Data to add to the file. Can be given as a block. - # flag<String>:: Flag of where to add the changes. - # log_status<Boolean>:: If false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config<Hash>:: give :verbose => false to not log the status and the flag + # for injection (:after or :before). # # ==== Examples # @@ -24,28 +23,29 @@ class Thor # def inject_into_file(destination, *args, &block) if block_given? - data, flag = block, args.shift + data, config = block, args.shift else - data, flag = args.shift, args.shift + data, config = args.shift, args.shift end log_status = args.empty? || args.pop - action InjectIntoFile.new(self, destination, data, flag, log_status) + action InjectIntoFile.new(self, destination, data, config) end class InjectIntoFile #:nodoc: - attr_reader :base, :destination, :relative_destination, :flag, :replacement + attr_reader :base, :destination, :relative_destination, :flag, :replacement, :config - def initialize(base, destination, data, flag, log_status=true) - @base, @log_status = base, log_status - behavior, @flag = flag.keys.first, flag.values.first + def initialize(base, destination, data, config) + @base, @config = base, { :verbose => true }.merge(config) self.destination = destination data = data.call if data.is_a?(Proc) - @replacement = if behavior == :after + @replacement = if @config.key?(:after) + @flag = @config.delete(:after) @flag + data else + @flag = @config.delete(:before) data + @flag end end @@ -75,7 +75,7 @@ class Thor # Shortcut to say_status shell method. # def say_status(status) - base.shell.say_status status, relative_destination, @log_status + base.shell.say_status status, relative_destination, config[:verbose] end # Adds the content to the file. diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/template.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/template.rb index 6b2e50b8c5..95e2412514 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/template.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/template.rb @@ -9,9 +9,9 @@ class Thor # to be equal to the source removing .tt from the filename. # # ==== Parameters - # source<String>:: the relative path to the source root - # destination<String>:: the relative path to the destination root - # log_status<Boolean>:: if false, does not log the status. True by default. + # source<String>:: the relative path to the source root. + # destination<String>:: the relative path to the destination root. + # config<Hash>:: give :verbose => false to not log the status. # # ==== Examples # @@ -19,9 +19,9 @@ class Thor # # template "doc/README" # - def template(source, destination=nil, log_status=true) + def template(source, destination=nil, config={}) destination ||= source.gsub(/.tt$/, '') - action Template.new(self, source, destination, log_status) + action Template.new(self, source, destination, config) end class Template < Templater #:nodoc: diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/templater.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/templater.rb index b4b7bae3af..455178c6e8 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/templater.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/templater.rb @@ -8,7 +8,7 @@ class Thor # by Jonas Nicklas and Michael S. Klishin under MIT LICENSE. # class Templater #:nodoc: - attr_reader :base, :source, :destination, :given_destination, :relative_destination + attr_reader :base, :source, :destination, :given_destination, :relative_destination, :config # Initializes given the source and destination. # @@ -16,11 +16,10 @@ class Thor # base<Thor::Base>:: A Thor::Base instance # source<String>:: Relative path to the source of this file # destination<String>:: Relative path to the destination of this file - # log_status<Boolean>:: If false, does not log the status. True by default. - # Templater log status does not accept color. + # config<Hash>:: give :verbose => false to not log the status. # - def initialize(base, source, destination, log_status=true) - @base, @log_status = base, log_status + def initialize(base, source, destination, config={}) + @base, @config = base, { :verbose => true }.merge(config) self.source = source self.destination = destination end @@ -56,7 +55,7 @@ class Thor # but you can modify in the subclass. # def invoke! - invoke_with_options!(base.options) do + invoke_with_options!(base.options.merge(config)) do ::FileUtils.mkdir_p(::File.dirname(destination)) ::File.open(destination, 'w'){ |f| f.write render } end @@ -187,7 +186,7 @@ class Thor # Shortcut to say_status shell method. # def say_status(status, color) - base.shell.say_status status, relative_destination, color if @log_status + base.shell.say_status status, relative_destination, color if config[:verbose] end end |