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 def conditions_met?(data) data[:conditions]&.each do |conditions_data| case conditions_data[:type] when "time_of_day" return false unless conditions_data[:times].include? World.time_of_day.to_s else raise "Invalid condition type GID (#{conditions_data[:type]})" end end true end end end