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