lib/unscoped_associations.rb in unscoped_associations-0.3.0 vs lib/unscoped_associations.rb in unscoped_associations-0.3.1

- old
+ new

@@ -10,51 +10,38 @@ end module ClassMethods def belongs_to_with_unscoped(name, options = {}) - if unscoped_attribute = options.delete(:unscoped) - add_unscoped_belongs_to(name, options) + if options.delete(:unscoped) + add_unscoped_association(name) end belongs_to_without_unscoped(name, options) end def has_many_with_unscoped(name, options = {}) - if unscoped_attribute = options.delete(:unscoped) - add_unscoped_has_many(name, options) + if options.delete(:unscoped) + add_unscoped_association(name) end has_many_without_unscoped(name, options) end def has_one_with_unscoped(name, options = {}) - if unscoped_attribute = options.delete(:unscoped) - add_unscoped_has_one(name, options) + if options.delete(:unscoped) + add_unscoped_association(name) end has_one_without_unscoped(name, options) end private - def add_unscoped_belongs_to(association_name, options) - define_unscoped_association(association_name, options) - end - - def add_unscoped_has_many(association_name, options) - define_unscoped_association(association_name, options) - end - - def add_unscoped_has_one(association_name, options) - define_unscoped_association(association_name, options) - end - - def define_unscoped_association(association_name, options) + def add_unscoped_association(association_name) define_method(association_name) do - self.class.reflect_on_association(association_name).klass.unscoped { + self.class.reflect_on_association(association_name).klass.unscoped do super(association_name) - } + end end end - end end ActiveRecord::Base.instance_eval { include UnscopedAssociations } \ No newline at end of file