Module: MakeTaggable::Tagger::InstanceMethods
- Defined in:
- lib/make_taggable/tagger.rb
Overview
Added to a model once it is a tagger.
Instance Method Summary collapse
- #is_tagger? ⇒ TrueClass, FalseClass
-
#tag(taggable, opts = {}) ⇒ TrueClass, FalseClass
Tags a record, with this tagger as the owner of the tags.
-
#tagger? ⇒ TrueClass, FalseClass
Whether this record claims ownership of the tags it applies.
Instance Method Details
#is_tagger? ⇒ TrueClass, FalseClass
125 126 127 |
# File 'lib/make_taggable/tagger.rb', line 125 def is_tagger? tagger? end |
#tag(taggable, opts = {}) ⇒ TrueClass, FalseClass
Tags a record, with this tagger as the owner of the tags.
The taggable is saved unless :skip_save is given, so the tags are persisted immediately.
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/make_taggable/tagger.rb', line 99 def tag(taggable, opts = {}) opts.reverse_merge!(force: true) skip_save = opts.delete(:skip_save) return false unless taggable.respond_to?(:is_taggable?) && taggable.is_taggable? fail "You need to specify a tag context using :on" unless opts.key?(:on) fail "You need to specify some tags using :with" unless opts.key?(:with) fail "No context :#{opts[:on]} defined in #{taggable.class}" unless opts[:force] || taggable.tag_types.include?(opts[:on]) taggable.set_owner_tag_list_on(self, opts[:on].to_s, opts[:with]) taggable.save unless skip_save end |
#tagger? ⇒ TrueClass, FalseClass
Whether this record claims ownership of the tags it applies.
117 118 119 |
# File 'lib/make_taggable/tagger.rb', line 117 def tagger? self.class.is_tagger? end |