Class: EasyTags::TaggableContext
- Inherits:
-
Object
- Object
- EasyTags::TaggableContext
- Defined in:
- lib/easy_tags/taggable_context.rb
Overview
Handles tag context manipulation
Instance Method Summary collapse
-
#add(*names) ⇒ Object
Add tags to the tag_list.
- #changed? ⇒ true, false
-
#initialize(context:, tags_association:, on_change:) ⇒ TaggableContext
constructor
A new instance of TaggableContext.
- #new_tags ⇒ TagList
- #persisted_tags ⇒ TagList
-
#refresh ⇒ Object
clear memoized info and force a refresh.
-
#remove(value) ⇒ Object
Remove item from list.
- #removed_tags ⇒ TagList
- #tags ⇒ TagList
- #update(value) ⇒ TagList
Constructor Details
#initialize(context:, tags_association:, on_change:) ⇒ TaggableContext
Returns a new instance of TaggableContext.
9 10 11 12 13 |
# File 'lib/easy_tags/taggable_context.rb', line 9 def initialize(context:, tags_association:, on_change:) self.context = context self. = self.on_change = on_change end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
85 86 87 88 89 |
# File 'lib/easy_tags/taggable_context.rb', line 85 def method_missing(name, *args, &block) return super unless respond_to_missing?(name) .send(name, *args, &block) end |
Instance Method Details
#add(*names) ⇒ Object
Add tags to the tag_list. Duplicate or blank tags will be ignored.
Example:
tag_list.add('Fun', 'Happy')
59 60 61 62 63 |
# File 'lib/easy_tags/taggable_context.rb', line 59 def add(*names) .add(*names).tap do notify_change end end |
#changed? ⇒ true, false
16 17 18 |
# File 'lib/easy_tags/taggable_context.rb', line 16 def changed? .sort != .sort end |
#persisted_tags ⇒ TagList
26 27 28 |
# File 'lib/easy_tags/taggable_context.rb', line 26 def @persisted_tags ||= end |
#refresh ⇒ Object
clear memoized info and force a refresh
49 50 51 52 53 |
# File 'lib/easy_tags/taggable_context.rb', line 49 def refresh @tags = nil @persisted_tags = nil .reset end |
#remove(value) ⇒ Object
Remove item from list
Example:
tag_list.remove('Issues')
69 70 71 72 73 |
# File 'lib/easy_tags/taggable_context.rb', line 69 def remove(value) .remove(value).tap do notify_change end end |