Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

correct usage of ActiveSupport::Concern

You should not use include inside an included block as this prevents
developers from extending any of the mongoid api in the correct way.
Module inclusion should build up the inheritance chain with each include,
so that the last included module is first in the chain. Including in an
included block kills this by insuring your module is included last.

Check out the source for ActiveSupport::Concern to see what I mean.
  • Loading branch information...
commit 6854503b3892f608ad92b37f0e99eddc9f2a2d09 1 parent ee64f1d
@adzap adzap authored
View
4 lib/mongoid/associations.rb
@@ -14,9 +14,9 @@
module Mongoid # :nodoc:
module Associations #:nodoc:
extend ActiveSupport::Concern
- included do
- include ForeignKey
+ include ForeignKey
+ included do
cattr_accessor :embedded
self.embedded = false
View
60 lib/mongoid/components.rb
@@ -2,39 +2,41 @@
module Mongoid #:nodoc
module Components #:nodoc
extend ActiveSupport::Concern
+
+ # All modules that a +Document+ is composed of are defined in this
+ # module, to keep the document class from getting too cluttered.
included do
- # All modules that a +Document+ is composed of are defined in this
- # module, to keep the document class from getting too cluttered.
- include ActiveModel::Conversion
- include ActiveModel::Naming
- include ActiveModel::Serialization
- include ActiveModel::MassAssignmentSecurity
- include ActiveModel::Serializers::JSON
- include ActiveModel::Serializers::Xml
- include Mongoid::Associations
- include Mongoid::Atomicity
- include Mongoid::Attributes
- include Mongoid::Collections
- include Mongoid::Dirty
- include Mongoid::Extras
- include Mongoid::Fields
- include Mongoid::Hierarchy
- include Mongoid::Indexes
- include Mongoid::JSON
- include Mongoid::Keys
- include Mongoid::Matchers
- include Mongoid::Memoization
- include Mongoid::Modifiers
- include Mongoid::MultiParameterAttributes
- include Mongoid::Paths
- include Mongoid::Persistence
- include Mongoid::Safety
- include Mongoid::State
- include Mongoid::Validations
- include Mongoid::Callbacks
extend ActiveModel::Translation
extend Mongoid::Finders
extend Mongoid::NamedScope
end
+
+ include ActiveModel::Conversion
+ include ActiveModel::Naming
+ include ActiveModel::Serialization
+ include ActiveModel::MassAssignmentSecurity
+ include ActiveModel::Serializers::JSON
+ include ActiveModel::Serializers::Xml
+ include Mongoid::Associations
+ include Mongoid::Atomicity
+ include Mongoid::Attributes
+ include Mongoid::Collections
+ include Mongoid::Dirty
+ include Mongoid::Extras
+ include Mongoid::Fields
+ include Mongoid::Hierarchy
+ include Mongoid::Indexes
+ include Mongoid::JSON
+ include Mongoid::Keys
+ include Mongoid::Matchers
+ include Mongoid::Memoization
+ include Mongoid::Modifiers
+ include Mongoid::MultiParameterAttributes
+ include Mongoid::Paths
+ include Mongoid::Persistence
+ include Mongoid::Safety
+ include Mongoid::State
+ include Mongoid::Validations
+ include Mongoid::Callbacks
end
end
View
4 lib/mongoid/document.rb
@@ -2,9 +2,9 @@
module Mongoid #:nodoc:
module Document
extend ActiveSupport::Concern
- included do
- include Mongoid::Components
+ include Mongoid::Components
+ included do
attr_accessor :association_name
attr_reader :new_record
end
Please sign in to comment.
Something went wrong with that request. Please try again.