blob: 22322c0b311dd177e38f4b781ac04e25046920dc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
module HasWhatnot
extend ActiveSupport::Concern
included do
def whatnot
@whatnot ||= super.is_a?(Hash) ? super.deep_symbolize_keys! : nil
end
def tags
whatnot && whatnot[:tags] ? whatnot[:tags] : []
end
def has_tag?(tag)
return false unless tags.any?
tags.include?(tag)
end
def where_has_tag(tag)
where("whatnot->'tags' ? :tag", tag: tag)
end
end
end
|