Module: MakeTaggable::Tagger::ClassMethods
- Defined in:
- lib/make_taggable/tagger.rb
Overview
Added to every Active Record model.
Instance Method Summary collapse
- #is_tagger? ⇒ TrueClass, FalseClass
-
#make_tagger(opts = {}) ⇒ void
Make a model a tagger, allowing its instances to claim ownership of the tags they apply.
-
#tagger? ⇒ TrueClass, FalseClass
Whether this model claims ownership of the tags it applies.
Instance Method Details
#is_tagger? ⇒ TrueClass, FalseClass
71 72 73 |
# File 'lib/make_taggable/tagger.rb', line 71 def is_tagger? tagger? end |
#make_tagger(opts = {}) ⇒ void
This method returns an undefined value.
Make a model a tagger, allowing its instances to claim ownership of the tags they apply.
Adds an owned_taggings association and an owned_tags association to the model.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/make_taggable/tagger.rb', line 37 def make_tagger(opts = {}) class_eval do owned_taggings_scope = opts.delete(:scope) has_many :owned_taggings, owned_taggings_scope, **opts.merge( as: :tagger, class_name: "::MakeTaggable::Tagging", dependent: :destroy ) has_many :owned_tags, -> { distinct }, class_name: MakeTaggable.tag_class, source: :tag, through: :owned_taggings end include MakeTaggable::Tagger::InstanceMethods extend MakeTaggable::Tagger::SingletonMethods end |
#tagger? ⇒ TrueClass, FalseClass
Whether this model claims ownership of the tags it applies.
63 64 65 |
# File 'lib/make_taggable/tagger.rb', line 63 def tagger? false end |