summaryrefslogtreecommitdiff
path: root/app/models/concerns/has_whatnot.rb
blob: a0934ef7c0f460fb28e195307310b3b5bd34eab0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module HasWhatnot
  extend ActiveSupport::Concern

  included do
    def whatnot
      @whatnot ||= super.is_a?(Hash) ? super.deep_symbolize_keys! : nil
    end

    def tags
      whatnot[:tags] ? whatnot[:tags] : []
    end

    def where_has_tag(tag)
      where("whatnot->'tags' ? :tag", tag: tag)
    end
  end
end