Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge commit 'jose/responder'

  • Loading branch information...
commit ad98827a78d0ee13c5d3b8c5caf2fccfa294277c 2 parents efcfce5 + 016ed9b
Yehuda Katz wycats authored
2  actionpack/lib/action_controller.rb
View
@@ -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"
26 actionpack/lib/action_controller/metal/mime_responds.rb
View
@@ -179,15 +179,15 @@ def clear_respond_to
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 @@ def respond_to(*mimes, &block)
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 @@ def respond_to(*mimes, &block)
# 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 @@ def collect_mimes_from_class_level #:nodoc:
end
end
- class Responder #:nodoc:
+ class Collector #:nodoc:
attr_accessor :order
def initialize
24 actionpack/lib/action_controller/metal/renderer.rb → actionpack/lib/action_controller/metal/responder.rb
View
@@ -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 @@ def initialize(controller, resource, options={})
# 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
10 actionpack/test/controller/mime_responds_test.rb
View
@@ -505,9 +505,9 @@ def using_resource_with_status_and_location
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 @@ def test_using_resource_with_status_and_location
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
64 railties/lib/generators.rb
View
@@ -83,6 +83,34 @@ def self.options #:nodoc:
@@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 @@ def self.no_color!
# 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 @@ def self.help
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 @@ def self.builtin #:nodoc:
#
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 @@ def self.lookup(attempts) #:nodoc:
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
14 railties/lib/generators/action_orm.rb → railties/lib/generators/active_model.rb
View
@@ -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 Generators
#
# 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)
4 railties/lib/generators/active_record.rb
View
@@ -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 @@ def next_migration_number(dirname) #:nodoc:
end
end
- class ActionORM < Rails::Generators::ActionORM #:nodoc:
+ class ActiveModel < Rails::Generators::ActiveModel #:nodoc:
def self.all(klass)
"#{klass}.all"
end
10 railties/lib/generators/named_base.rb
View
@@ -124,18 +124,18 @@ def initialize(*args) #:nodoc:
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 @@ def orm_class
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)
0  ...ndor/gems/mspec/lib/generators/mspec_generator.rb → ...gems/gems/mspec/lib/generators/mspec_generator.rb
View
File renamed without changes
0  ...ndor/gems/wrong/lib/generators/wrong_generator.rb → ...gems/gems/wrong/lib/generators/wrong_generator.rb
View
File renamed without changes
2  railties/test/generators/scaffold_controller_generator_test.rb
View
@@ -99,7 +99,7 @@ def test_skip_layout_if_required
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
Please sign in to comment.
Something went wrong with that request. Please try again.