Module: EasyTags::Taggable::ClassMethods
- Defined in:
- lib/easy_tags/taggable.rb
Instance Method Summary collapse
-
#easy_tags_on(*tagging_contexts_params) ⇒ Object
rubocop:enable Style/Documentation.
Instance Method Details
#easy_tags_on(*tagging_contexts_params) ⇒ Object
rubocop:enable Style/Documentation
Examples
:highlights
with multiple contexts:
:highlights, :tags
with callbacks:
(
highlights: {
after_add: :add_tag_callback, after_remove: ->(tagging) { puts "removed #{tagging.tag.name}" }
}
)
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/easy_tags/taggable.rb', line 26 def (*tagging_contexts_params) cattr_accessor :tagging_contexts cattr_accessor :tagging_callbacks = Options::Collection.new(tagging_contexts_params.to_a) raise 'invalid options' unless .valid? self.tagging_contexts ||= [] self.tagging_callbacks ||= {} .items.each do |option| tagging_contexts.push(option.name) unless tagging_contexts.include?(option.name) tagging_callbacks[option.name] = option.callbacks EasyTags::TaggableContextMethods.inject( class_instance: self, context: option.name ) end end |