aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_controller.rb2
-rw-r--r--actionpack/lib/action_controller/metal/mime_responds.rb26
-rw-r--r--actionpack/lib/action_controller/metal/responder.rb (renamed from actionpack/lib/action_controller/metal/renderer.rb)24
-rw-r--r--actionpack/test/controller/mime_responds_test.rb10
-rw-r--r--railties/lib/generators.rb64
-rw-r--r--railties/lib/generators/active_model.rb (renamed from railties/lib/generators/action_orm.rb)14
-rw-r--r--railties/lib/generators/active_record.rb4
-rw-r--r--railties/lib/generators/named_base.rb10
-rw-r--r--railties/test/fixtures/vendor/gems/gems/mspec/lib/generators/mspec_generator.rb (renamed from railties/test/fixtures/vendor/gems/mspec/lib/generators/mspec_generator.rb)0
-rw-r--r--railties/test/fixtures/vendor/gems/gems/wrong/lib/generators/wrong_generator.rb (renamed from railties/test/fixtures/vendor/gems/wrong/lib/generators/wrong_generator.rb)0
-rw-r--r--railties/test/generators/scaffold_controller_generator_test.rb2
11 files changed, 89 insertions, 67 deletions
diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb
index 8343a87936..37ff618edd 100644
--- a/actionpack/lib/action_controller.rb
+++ b/actionpack/lib/action_controller.rb
@@ -7,10 +7,10 @@ module ActionController
autoload :RackConvenience, "action_controller/metal/rack_convenience"
autoload :Rails2Compatibility, "action_controller/metal/compatibility"
autoload :Redirector, "action_controller/metal/redirector"
- autoload :Renderer, "action_controller/metal/renderer"
autoload :RenderingController, "action_controller/metal/rendering_controller"
autoload :RenderOptions, "action_controller/metal/render_options"
autoload :Rescue, "action_controller/metal/rescuable"
+ autoload :Responder, "action_controller/metal/responder"
autoload :Testing, "action_controller/metal/testing"
autoload :UrlFor, "action_controller/metal/url_for"
autoload :Session, "action_controller/metal/session"
diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb
index d823dd424a..c8d042acb5 100644
--- a/actionpack/lib/action_controller/metal/mime_responds.rb
+++ b/actionpack/lib/action_controller/metal/mime_responds.rb
@@ -179,15 +179,15 @@ module ActionController #:nodoc:
def respond_to(*mimes, &block)
raise ArgumentError, "respond_to takes either types or a block, never both" if mimes.any? && block_given?
- responder = Responder.new
+ collector = Collector.new
mimes = collect_mimes_from_class_level if mimes.empty?
- mimes.each { |mime| responder.send(mime) }
- block.call(responder) if block_given?
+ mimes.each { |mime| collector.send(mime) }
+ block.call(collector) if block_given?
- if format = request.negotiate_mime(responder.order)
+ if format = request.negotiate_mime(collector.order)
self.formats = [format.to_sym]
- if response = responder.response_for(format)
+ if response = collector.response_for(format)
response.call
else
default_render
@@ -197,10 +197,10 @@ module ActionController #:nodoc:
end
end
- # respond_with wraps a resource around a renderer for default representation.
+ # respond_with wraps a resource around a responder for default representation.
# First it invokes respond_to, if a response cannot be found (ie. no block
# for the request was given and template was not available), it instantiates
- # an ActionController::Renderer with the controller and resource.
+ # an ActionController::Responder with the controller and resource.
#
# ==== Example
#
@@ -221,19 +221,19 @@ module ActionController #:nodoc:
# end
# end
#
- # All options given to respond_with are sent to the underlying renderer,
- # except for the option :renderer itself. Since the renderer interface
+ # All options given to respond_with are sent to the underlying responder,
+ # except for the option :responder itself. Since the responder interface
# is quite simple (it just needs to respond to call), you can even give
# a proc to it.
#
def respond_with(resource, options={}, &block)
respond_to(&block)
rescue ActionView::MissingTemplate
- (options.delete(:renderer) || renderer).call(self, resource, options)
+ (options.delete(:responder) || responder).call(self, resource, options)
end
- def renderer
- ActionController::Renderer
+ def responder
+ ActionController::Responder
end
protected
@@ -257,7 +257,7 @@ module ActionController #:nodoc:
end
end
- class Responder #:nodoc:
+ class Collector #:nodoc:
attr_accessor :order
def initialize
diff --git a/actionpack/lib/action_controller/metal/renderer.rb b/actionpack/lib/action_controller/metal/responder.rb
index 39ab2407aa..9ed99ca623 100644
--- a/actionpack/lib/action_controller/metal/renderer.rb
+++ b/actionpack/lib/action_controller/metal/responder.rb
@@ -1,6 +1,6 @@
module ActionController #:nodoc:
- # Renderer is responsible to expose a resource for different mime requests,
- # usually depending on the HTTP verb. The renderer is triggered when
+ # Responder is responsible to expose a resource for different mime requests,
+ # usually depending on the HTTP verb. The responder is triggered when
# respond_with is called. The simplest case to study is a GET request:
#
# class PeopleController < ApplicationController
@@ -16,17 +16,17 @@ module ActionController #:nodoc:
#
# 1) respond_with searches for a template at people/index.xml;
#
- # 2) if the template is not available, it will create a renderer, passing
+ # 2) if the template is not available, it will create a responder, passing
# the controller and the resource and invoke :to_xml on it;
#
- # 3) if the renderer does not respond_to :to_xml, call to_format on it.
+ # 3) if the responder does not respond_to :to_xml, call to_format on it.
#
# === Builtin HTTP verb semantics
#
- # Rails default renderer holds semantics for each HTTP verb. Depending on the
+ # Rails default responder holds semantics for each HTTP verb. Depending on the
# content type, verb and the resource status, it will behave differently.
#
- # Using Rails default renderer, a POST request for creating an object could
+ # Using Rails default responder, a POST request for creating an object could
# be written as:
#
# def create
@@ -67,7 +67,7 @@ module ActionController #:nodoc:
# respond_with([@project, @task])
# end
#
- # Giving an array of resources, you ensure that the renderer will redirect to
+ # Giving an array of resources, you ensure that the responder will redirect to
# project_task_url instead of task_url.
#
# Namespaced and singleton resources requires a symbol to be given, as in
@@ -78,7 +78,7 @@ module ActionController #:nodoc:
#
# Check polymorphic_url documentation for more examples.
#
- class Renderer
+ class Responder
attr_reader :controller, :request, :format, :resource, :resource_location, :options
def initialize(controller, resource, options={})
@@ -96,13 +96,13 @@ module ActionController #:nodoc:
# Undefine :to_json since it's defined on Object
undef_method :to_json
- # Initializes a new renderer an invoke the proper format. If the format is
+ # Initializes a new responder an invoke the proper format. If the format is
# not defined, call to_format.
#
def self.call(*args)
- renderer = new(*args)
- method = :"to_#{renderer.format}"
- renderer.respond_to?(method) ? renderer.send(method) : renderer.to_format
+ responder = new(*args)
+ method = :"to_#{responder.format}"
+ responder.respond_to?(method) ? responder.send(method) : responder.to_format
end
# HTML format does not render the resource, it always attempt to render a
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 00ad90ff68..8319b5c573 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -505,9 +505,9 @@ class RespondWithController < ActionController::Base
respond_with(Customer.new("david", 13), :location => "http://test.host/", :status => :created)
end
- def using_resource_with_renderer
- renderer = proc { |c, r, o| c.render :text => "Resource name is #{r.name}" }
- respond_with(Customer.new("david", 13), :renderer => renderer)
+ def using_resource_with_responder
+ responder = proc { |c, r, o| c.render :text => "Resource name is #{r.name}" }
+ respond_with(Customer.new("david", 13), :responder => responder)
end
protected
@@ -743,8 +743,8 @@ class RespondWithControllerTest < ActionController::TestCase
assert_equal 201, @response.status
end
- def test_using_resource_with_renderer
- get :using_resource_with_renderer
+ def test_using_resource_with_responder
+ get :using_resource_with_responder
assert_equal "Resource name is david", @response.body
end
diff --git a/railties/lib/generators.rb b/railties/lib/generators.rb
index ef837e1488..c97c61507a 100644
--- a/railties/lib/generators.rb
+++ b/railties/lib/generators.rb
@@ -83,6 +83,34 @@ module Rails
@@options ||= DEFAULT_OPTIONS.dup
end
+ # Get paths only from loaded rubygems. In other words, to use rspec
+ # generators, you first have to ensure that rspec gem was already loaded.
+ #
+ def self.rubygems_generators_paths
+ paths = []
+ return paths unless defined?(Gem)
+
+ Gem.loaded_specs.each do |name, spec|
+ generator_path = File.join(spec.full_gem_path, "lib/generators")
+ paths << generator_path if File.exist?(generator_path)
+ end
+
+ paths
+ end
+
+ # If RAILS_ROOT is defined, add vendor/gems, vendor/plugins and lib/generators
+ # paths.
+ #
+ def self.rails_root_generators_paths
+ paths = []
+ if defined?(RAILS_ROOT)
+ paths += Dir[File.join(RAILS_ROOT, "vendor", "gems", "gems", "*", "lib", "generators")]
+ paths += Dir[File.join(RAILS_ROOT, "vendor", "plugins", "*", "lib", "generators")]
+ paths << File.join(RAILS_ROOT, "lib", "generators")
+ end
+ paths
+ end
+
# Hold configured generators fallbacks. If a plugin developer wants a
# generator group to fallback to another group in case of missing generators,
# they can add a fallback.
@@ -108,30 +136,25 @@ module Rails
# Generators load paths used on lookup. The lookup happens as:
#
- # 1) builtin generators
- # 2) frozen gems generators
- # 3) rubygems gems generators (not available yet)
- # 4) plugin generators
- # 5) lib generators
- # 6) ~/rails/generators
+ # 1) lib generators
+ # 2) vendor/plugin generators
+ # 3) vendor/gems generators
+ # 4) ~/rails/generators
+ # 5) rubygems generators
+ # 6) builtin generators
#
- # TODO Add Rubygems generators (depends on dependencies system rework)
# TODO Remove hardcoded paths for all, except (1).
#
- def self.load_path
- @@load_path ||= begin
- paths = []
- paths << File.expand_path(File.join(File.dirname(__FILE__), "generators"))
- if defined?(RAILS_ROOT)
- paths += Dir[File.join(RAILS_ROOT, "vendor", "gems", "*", "lib", "generators")]
- paths += Dir[File.join(RAILS_ROOT, "vendor", "plugins", "*", "lib", "generators")]
- paths << File.join(RAILS_ROOT, "lib", "generators")
- end
+ def self.load_paths
+ @@load_paths ||= begin
+ paths = self.rails_root_generators_paths
paths << File.join(Thor::Util.user_home, ".rails", "generators")
+ paths += self.rubygems_generators_paths
+ paths << File.expand_path(File.join(File.dirname(__FILE__), "generators"))
paths
end
end
- load_path # Cache load paths. Needed to avoid __FILE__ pointing to wrong paths.
+ load_paths # Cache load paths. Needed to avoid __FILE__ pointing to wrong paths.
# Receives a namespace and tries different combinations to find a generator.
#
@@ -204,8 +227,8 @@ module Rails
puts "Builtin: #{rails.join(', ')}."
# Load paths and remove builtin
- paths, others = load_path.dup, []
- paths.shift
+ paths, others = load_paths.dup, []
+ paths.pop
paths.each do |path|
tail = [ "*", "*", "*_generator.rb" ]
@@ -242,7 +265,6 @@ module Rails
#
def self.invoke_fallbacks_for(name, base)
return nil unless base && fallbacks[base.to_sym]
-
invoked_fallbacks = []
Array(fallbacks[base.to_sym]).each do |fallback|
@@ -283,7 +305,7 @@ module Rails
generators_path.uniq!
generators_path = "{#{generators_path.join(',')}}"
- self.load_path.each do |path|
+ self.load_paths.each do |path|
Dir[File.join(path, generators_path, name)].each do |file|
begin
require file
diff --git a/railties/lib/generators/action_orm.rb b/railties/lib/generators/active_model.rb
index 69cf227fd7..1a849a0e02 100644
--- a/railties/lib/generators/action_orm.rb
+++ b/railties/lib/generators/active_model.rb
@@ -1,6 +1,6 @@
module Rails
module Generators
- # ActionORM is a class to be implemented by each ORM to allow Rails to
+ # ActiveModel is a class to be implemented by each ORM to allow Rails to
# generate customized controller code.
#
# The API has the same methods as ActiveRecord, but each method returns a
@@ -8,22 +8,22 @@ module Rails
#
# For example:
#
- # ActiveRecord::Generators::ActionORM.find(Foo, "params[:id]")
+ # ActiveRecord::Generators::ActiveModel.find(Foo, "params[:id]")
# #=> "Foo.find(params[:id])"
#
- # Datamapper::Generators::ActionORM.find(Foo, "params[:id]")
+ # Datamapper::Generators::ActiveModel.find(Foo, "params[:id]")
# #=> "Foo.get(params[:id])"
#
- # On initialization, the ActionORM accepts the instance name that will
+ # On initialization, the ActiveModel accepts the instance name that will
# receive the calls:
#
- # builder = ActiveRecord::Generators::ActionORM.new "@foo"
+ # builder = ActiveRecord::Generators::ActiveModel.new "@foo"
# builder.save #=> "@foo.save"
#
- # The only exception in ActionORM for ActiveRecord is the use of self.build
+ # The only exception in ActiveModel for ActiveRecord is the use of self.build
# instead of self.new.
#
- class ActionORM
+ class ActiveModel
attr_reader :name
def initialize(name)
diff --git a/railties/lib/generators/active_record.rb b/railties/lib/generators/active_record.rb
index 64bee3904e..924b70881a 100644
--- a/railties/lib/generators/active_record.rb
+++ b/railties/lib/generators/active_record.rb
@@ -1,6 +1,6 @@
require 'generators/named_base'
require 'generators/migration'
-require 'generators/action_orm'
+require 'generators/active_model'
require 'active_record'
module ActiveRecord
@@ -20,7 +20,7 @@ module ActiveRecord
end
end
- class ActionORM < Rails::Generators::ActionORM #:nodoc:
+ class ActiveModel < Rails::Generators::ActiveModel #:nodoc:
def self.all(klass)
"#{klass}.all"
end
diff --git a/railties/lib/generators/named_base.rb b/railties/lib/generators/named_base.rb
index 699b8ed651..9632e6806c 100644
--- a/railties/lib/generators/named_base.rb
+++ b/railties/lib/generators/named_base.rb
@@ -124,18 +124,18 @@ module Rails
protected
- # Loads the ORM::Generators::ActionORM class. This class is responsable
+ # Loads the ORM::Generators::ActiveModel class. This class is responsable
# to tell scaffold entities how to generate an specific method for the
- # ORM. Check Rails::Generators::ActionORM for more information.
+ # ORM. Check Rails::Generators::ActiveModel for more information.
#
def orm_class
@orm_class ||= begin
# Raise an error if the class_option :orm was not defined.
unless self.class.class_options[:orm]
- raise "You need to have :orm as class option to invoke orm_class and orm_instance"
+ raise "You need to have :orm as class option to invoke orm_class and orm_instance"
end
- action_orm = "#{options[:orm].to_s.classify}::Generators::ActionORM"
+ action_orm = "#{options[:orm].to_s.classify}::Generators::ActiveModel"
# If the orm was not loaded, try to load it at "generators/orm",
# for example "generators/active_record" or "generators/sequel".
@@ -152,7 +152,7 @@ module Rails
end
end
- # Initialize ORM::Generators::ActionORM to access instance methods.
+ # Initialize ORM::Generators::ActiveModel to access instance methods.
#
def orm_instance(name=file_name)
@orm_instance ||= @orm_class.new(name)
diff --git a/railties/test/fixtures/vendor/gems/mspec/lib/generators/mspec_generator.rb b/railties/test/fixtures/vendor/gems/gems/mspec/lib/generators/mspec_generator.rb
index 191bdbf2fc..191bdbf2fc 100644
--- a/railties/test/fixtures/vendor/gems/mspec/lib/generators/mspec_generator.rb
+++ b/railties/test/fixtures/vendor/gems/gems/mspec/lib/generators/mspec_generator.rb
diff --git a/railties/test/fixtures/vendor/gems/wrong/lib/generators/wrong_generator.rb b/railties/test/fixtures/vendor/gems/gems/wrong/lib/generators/wrong_generator.rb
index 6aa7cb052e..6aa7cb052e 100644
--- a/railties/test/fixtures/vendor/gems/wrong/lib/generators/wrong_generator.rb
+++ b/railties/test/fixtures/vendor/gems/gems/wrong/lib/generators/wrong_generator.rb
diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb
index 024ea439ef..834e43e776 100644
--- a/railties/test/generators/scaffold_controller_generator_test.rb
+++ b/railties/test/generators/scaffold_controller_generator_test.rb
@@ -99,7 +99,7 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase
def test_error_is_shown_if_orm_does_not_provide_interface
error = capture(:stderr){ run_generator ["User", "--orm=unknown"] }
- assert_equal "Could not load Unknown::Generators::ActionORM, skipping controller. " <<
+ assert_equal "Could not load Unknown::Generators::ActiveModel, skipping controller. " <<
"Error: no such file to load -- generators/unknown.\n", error
end