Module: Inform::Taggable
Overview
Instance Method Summary
collapse
Methods included from TagHelpers
#attributes, #has, #has?, #hasany?, #hasnt, #hasnt?
Instance Method Details
230
231
232
233
234
235
236
237
|
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 230
def nil_safe_tags
attempt_twice do
log.warn "The tags for #{self} is nil" if self.tags.nil?
self.tags.compact.map(&:to_s).map(&:intern)
end || Array::Empty
end
|
#tag(*args) ⇒ Object
rubocop: disable Metrics/AbcSize rubocop: disable Metrics/MethodLength
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 176
def tag(*args)
workflags.add(self.identity) if args.delete(:workflag)
a = self.tag_names args
(a - (self.nil_safe_tags & a)).each do |tag|
if Inform.tag_klass.respond_to?(:find_or_create)
add_tag(Inform.tag_klass.find_or_create(name: tag.to_s))
else
tag = tags.find { |tag| tag.name == tag.to_s } || Inform.tag_klass.new(tag.to_s)
add_tag(tag)
end
end
self.save_changes if self.respond_to?(:save_changes)
end
|
#tag_names(a) ⇒ Object
226
227
228
|
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 226
def tag_names(a)
a.flatten.map(&:to_s).map(&:intern)
end
|
#tagged_with?(tag) ⇒ Boolean
203
204
205
|
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 203
def tagged_with?(tag)
tagged_with_any? tag
end
|
#tagged_with_all?(*args) ⇒ Boolean
207
208
209
210
211
212
|
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 207
def tagged_with_all?(*args)
return workflags.include?(self.identity) if args.delete(:workflag)
a = self.tag_names(args)
(self.nil_safe_tags & a).length == a.length
end
|
#tagged_with_any?(*args) ⇒ Boolean
214
215
216
217
|
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 214
def tagged_with_any?(*args)
(args.delete(:workflag) && workflags.include?(self.identity)) || !self.tagged_with_none?(*tag_names(args))
end
|
#tagged_with_none?(*args) ⇒ Boolean
219
220
221
222
223
224
|
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 219
def tagged_with_none?(*args)
return false if args.delete(:workflag) && workflags.include?(self.identity)
!nil_safe_tags.intersect?(tag_names(args))
end
|
#untag(*args) ⇒ Object
Also known as:
tag!
rubocop: enable Metrics/AbcSize rubocop: enable Metrics/MethodLength
193
194
195
196
197
198
199
200
|
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 193
def untag(*args)
workflags.delete(self.identity) if args.delete(:workflag)
(self.nil_safe_tags & tag_names(args)).each do |tag|
remove_tag(Inform.tag_klass.find(name: tag.to_s))
end
self.save_changes if self.respond_to?(:save_changes)
end
|