Deprecate ActiveRecord#Base.default_scopes? #10113

Merged
merged 2 commits into from Apr 6, 2013

2 participants

@agis-

Fixes #10107.

@agis-

So what do you think? @rafaelfranca

@wangjohn wangjohn and 1 other commented on an outdated diff Apr 6, 2013
guides/source/active_support_core_extensions.md
@@ -1039,6 +1039,8 @@ For convenience `class_attribute` also defines an instance predicate which is th
When `:instance_reader` is `false`, the instance predicate returns a `NoMethodError` just like the reader method.
+If you do not want the instance predicate, pass `:skip_instance_predicate => true` and it wonill not be defined.
@wangjohn
wangjohn added a line comment Apr 6, 2013

Typo here, it should probably be "it will not be defined."

@agis-
agis- added a line comment Apr 6, 2013

Fixed, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rafaelfranca rafaelfranca and 1 other commented on an outdated diff Apr 6, 2013
...upport/lib/active_support/core_ext/class/attribute.rb
@@ -75,7 +76,7 @@ def class_attribute(*attrs)
attrs.each do |name|
define_singleton_method(name) { nil }
- define_singleton_method("#{name}?") { !!public_send(name) }
+ define_singleton_method("#{name}?") { !!public_send(name) } unless options[:skip_instance_predicate]
@rafaelfranca
Ruby on Rails member
rafaelfranca added a line comment Apr 6, 2013

I think is better to use the same convention and call this option instance_predicate

@agis-
agis- added a line comment Apr 6, 2013

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rafaelfranca rafaelfranca commented on an outdated diff Apr 6, 2013
activerecord/lib/active_record/scoping/default.rb
@@ -5,7 +5,8 @@ module Default
included do
# Stores the default scope for the class.
- class_attribute :default_scopes, instance_writer: false
+ class_attribute :default_scopes, instance_writer: false,
+ skip_instance_predicate: true
@rafaelfranca
Ruby on Rails member
rafaelfranca added a line comment Apr 6, 2013

We will need to deprecated the instance predicate here. We don't know how use it right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rafaelfranca
Ruby on Rails member

@Agis- very good. I made some comments.

Thank you

@rafaelfranca rafaelfranca commented on an outdated diff Apr 6, 2013
...upport/lib/active_support/core_ext/class/attribute.rb
@@ -72,10 +73,11 @@ def class_attribute(*attrs)
# double assignment is used to avoid "assigned but unused variable" warning
instance_reader = instance_reader = options.fetch(:instance_accessor, true) && options.fetch(:instance_reader, true)
instance_writer = options.fetch(:instance_accessor, true) && options.fetch(:instance_writer, true)
+ instance_predicate = !options.fetch(:skip_instance_predicate, false)
@rafaelfranca
Ruby on Rails member
rafaelfranca added a line comment Apr 6, 2013

I'm talking about changing the key name to instance_predicate like the others, with default to true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@carlosantoniodasilva carlosantoniodasilva and 1 other commented on an outdated diff Apr 6, 2013
guides/source/active_support_core_extensions.md
@@ -1039,6 +1039,8 @@ For convenience `class_attribute` also defines an instance predicate which is th
When `:instance_reader` is `false`, the instance predicate returns a `NoMethodError` just like the reader method.
+If you do not want the instance predicate, pass `:skip_instance_predicate => true` and it will not be defined.
@carlosantoniodasilva
Ruby on Rails member
carlosantoniodasilva added a line comment Apr 6, 2013

Make sure to use 1.9 style hash throughout your changes ;)

@agis-
agis- added a line comment Apr 6, 2013

Cool :) Even in tests where all the other cases are using the old style?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@agis-

@rafaelfranca Updated :)

@rafaelfranca
Ruby on Rails member

Seems good. Could you rebase your branch and squash your commits?

@rafaelfranca rafaelfranca merged commit a9da549 into rails:master Apr 6, 2013
@rafaelfranca
Ruby on Rails member

Thank you

@agis- agis- deleted the unknown repository branch Apr 6, 2013
@carlosantoniodasilva carlosantoniodasilva commented on the diff Apr 7, 2013
activerecord/lib/active_record/scoping/default.rb
self.default_scopes = []
+
+ def self.default_scopes?
+ ActiveSupport::Deprecation.warn(
+ "#default_scopes? is deprecated. Do something like #default_scopes.empty? instead."
+ )
+
+ !!self.default_scopes
+ end
@carlosantoniodasilva
Ruby on Rails member
carlosantoniodasilva added a line comment Apr 7, 2013

What if we fixed this implementation to check for default_scopes.empty? instead?

@agis-
agis- added a line comment Apr 7, 2013

Then that would make more sense :) I'll open a PR.

@rafaelfranca
Ruby on Rails member
rafaelfranca added a line comment Apr 7, 2013

I'd not do this. I think we should discourage this method, not implement the proper behavior, since it only exist by mistake.

@agis-
agis- added a line comment Apr 7, 2013

Really can't make my mind on this, both opinions are valid. Btw, the PR: #10129.

@carlosantoniodasilva
Ruby on Rails member
carlosantoniodasilva added a line comment Apr 8, 2013

Alright, now I wonder how many mistakes we have out there ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment