diff options
-rw-r--r-- | activesupport/CHANGELOG.md | 6 | ||||
-rw-r--r-- | activesupport/lib/active_support.rb | 1 | ||||
-rw-r--r-- | activesupport/lib/active_support/basic_object.rb | 16 | ||||
-rw-r--r-- | activesupport/lib/active_support/duration.rb | 4 | ||||
-rw-r--r-- | activesupport/lib/active_support/proxy_object.rb | 13 | ||||
-rw-r--r-- | activesupport/test/core_ext/duration_test.rb | 4 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb | 13 |
7 files changed, 36 insertions, 21 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 450669968b..f5f2aa85ef 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,5 +1,11 @@ ## Rails 4.0.0 (unreleased) ## +* Deprecate `ActiveSupport::BasicObject` in favor of `ActiveSupport::ProxyObject`. + This class is used for proxy classes. It avoids confusion with Ruby's BasicObject + class. + + *Francesco Rodriguez* + * Patched Marshal#load to work with constant autoloading. Fixes autoloading with cache stores that relay on Marshal(MemCacheStore and FileStore). [fixes #8167] diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb index 4e397ea110..b602686114 100644 --- a/activesupport/lib/active_support.rb +++ b/activesupport/lib/active_support.rb @@ -40,6 +40,7 @@ module ActiveSupport eager_autoload do autoload :BacktraceCleaner autoload :BasicObject + autoload :ProxyObject autoload :Benchmarkable autoload :Cache autoload :Callbacks diff --git a/activesupport/lib/active_support/basic_object.rb b/activesupport/lib/active_support/basic_object.rb index 6ccb0cd525..242b766b58 100644 --- a/activesupport/lib/active_support/basic_object.rb +++ b/activesupport/lib/active_support/basic_object.rb @@ -1,13 +1,7 @@ -module ActiveSupport - # A class with no predefined methods that behaves similarly to Builder's - # BlankSlate. Used for proxy classes. - class BasicObject < ::BasicObject - undef_method :== - undef_method :equal? +require 'active_support/deprecation' - # Let ActiveSupport::BasicObject at least raise exceptions. - def raise(*args) - ::Object.send(:raise, *args) - end - end +module ActiveSupport + # :nodoc: + # Deprecated in favor of ActiveSupport::ProxyObject + BasicObject = Deprecation::DeprecatedConstantProxy.new('ActiveSupport::BasicObject', 'ActiveSupport::ProxyObject') end diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index 7e99646117..2cb1f408b6 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -1,4 +1,4 @@ -require 'active_support/basic_object' +require 'active_support/proxy_object' require 'active_support/core_ext/array/conversions' require 'active_support/core_ext/object/acts_like' @@ -7,7 +7,7 @@ module ActiveSupport # Time#advance, respectively. It mainly supports the methods on Numeric. # # 1.month.ago # equivalent to Time.now.advance(months: -1) - class Duration < BasicObject + class Duration < ProxyObject attr_accessor :value, :parts def initialize(value, parts) #:nodoc: diff --git a/activesupport/lib/active_support/proxy_object.rb b/activesupport/lib/active_support/proxy_object.rb new file mode 100644 index 0000000000..a2bdf1d790 --- /dev/null +++ b/activesupport/lib/active_support/proxy_object.rb @@ -0,0 +1,13 @@ +module ActiveSupport + # A class with no predefined methods that behaves similarly to Builder's + # BlankSlate. Used for proxy classes. + class ProxyObject < ::BasicObject + undef_method :== + undef_method :equal? + + # Let ActiveSupport::BasicObject at least raise exceptions. + def raise(*args) + ::Object.send(:raise, *args) + end + end +end diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index c8312aa653..2826f51f2d 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -21,7 +21,7 @@ class DurationTest < ActiveSupport::TestCase assert ActiveSupport::Duration === 1.day assert !(ActiveSupport::Duration === 1.day.to_i) assert !(ActiveSupport::Duration === 'foo') - assert !(ActiveSupport::Duration === ActiveSupport::BasicObject.new) + assert !(ActiveSupport::Duration === ActiveSupport::ProxyObject.new) end def test_equals @@ -131,7 +131,7 @@ class DurationTest < ActiveSupport::TestCase assert_equal Time.local(2009,3,29,0,0,0) + 1.day, Time.local(2009,3,30,0,0,0) end end - + def test_delegation_with_block_works counter = 0 assert_nothing_raised do diff --git a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb index d6bce40b0c..5fc4ab8f6c 100644 --- a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +++ b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb @@ -4,6 +4,8 @@ require_dependency "<%= namespaced_file_path %>/application_controller" <% end -%> <% module_namespacing do -%> class <%= controller_class_name %>Controller < ApplicationController + before_action :set_<%= singular_table_name %>, except: [ :index, :new, :create ] + # GET <%= route_url %> # GET <%= route_url %>.json def index @@ -18,8 +20,6 @@ class <%= controller_class_name %>Controller < ApplicationController # GET <%= route_url %>/1 # GET <%= route_url %>/1.json def show - @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %> - respond_to do |format| format.html # show.html.erb format.json { render json: <%= "@#{singular_table_name}" %> } @@ -39,7 +39,6 @@ class <%= controller_class_name %>Controller < ApplicationController # GET <%= route_url %>/1/edit def edit - @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %> end # POST <%= route_url %> @@ -61,8 +60,6 @@ class <%= controller_class_name %>Controller < ApplicationController # PATCH/PUT <%= route_url %>/1 # PATCH/PUT <%= route_url %>/1.json def update - @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %> - respond_to do |format| if @<%= orm_instance.update_attributes("#{singular_table_name}_params") %> format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> } @@ -77,7 +74,6 @@ class <%= controller_class_name %>Controller < ApplicationController # DELETE <%= route_url %>/1 # DELETE <%= route_url %>/1.json def destroy - @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %> @<%= orm_instance.destroy %> respond_to do |format| @@ -86,7 +82,12 @@ class <%= controller_class_name %>Controller < ApplicationController end end + private + # Use callbacks to share common setup or constraints between actions. + def set_<%= singular_table_name %> + @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %> + end # Use this method to whitelist the permissible parameters. Example: params.require(:person).permit(:name, :age) # Also, you can specialize this method with per-user checking of permissible attributes. |