Skip to content

Commit 2785aea

Browse files
committed
Use ActiveSupport::Concern in the style of Mongoid 2.x
1 parent ba35684 commit 2785aea

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

lib/mongoid/taggable.rb

+11-15
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,20 @@
1313
# limitations under the License.
1414

1515
module Mongoid::Taggable
16-
def self.included(base)
17-
# create fields for tags and index it
18-
base.field :tags_array, :type => Array
19-
base.index [['tags_array', Mongo::ASCENDING]]
20-
21-
# add callback to save tags index
22-
base.after_save do |document|
16+
extend ActiveSupport::Concern
17+
18+
included do
19+
field :tags_array, :type => Array
20+
index [['tags_array', Mongo::ASCENDING]]
21+
22+
set_callback :save, :after do |document|
2323
document.class.save_tags_index!
2424
end
25-
26-
# extend model
27-
base.extend ClassMethods
28-
base.send :include, InstanceMethods
29-
30-
# enable indexing as default
31-
base.enable_tags_index!
25+
26+
# enable tag weight indexing as default
27+
enable_tags_index!
3228
end
33-
29+
3430
module ClassMethods
3531
# get an array with all defined tags for this model, this list returns
3632
# an array of distinct ordered list of tags defined in all documents

lib/mongoid_taggable.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
require 'active_support/concern'
2+
13
require File.join(File.dirname(__FILE__), 'mongoid/taggable')

0 commit comments

Comments
 (0)