47 lines
1.2 KiB
Ruby
47 lines
1.2 KiB
Ruby
class Filter < ApplicationRecord
|
|
include Fields, Params, Resources, Summarized
|
|
|
|
belongs_to :creator, class_name: "User", default: -> { Current.user }
|
|
has_one :account, through: :creator
|
|
|
|
class << self
|
|
def persist!(attrs)
|
|
create!(attrs)
|
|
rescue ActiveRecord::RecordNotUnique
|
|
find_by!(params_digest: digest_params(attrs)).tap(&:touch)
|
|
end
|
|
|
|
def digest_params(params)
|
|
Digest::MD5.hexdigest params.to_json
|
|
end
|
|
end
|
|
|
|
def empty?
|
|
as_params.blank?
|
|
end
|
|
|
|
def bubbles
|
|
@bubbles ||= begin
|
|
result = creator.accessible_bubbles.indexed_by(indexed_by)
|
|
result = result.active unless indexed_by.popped?
|
|
result = result.unassigned if assignments.unassigned?
|
|
result = result.assigned_to(assignees.ids) if assignees.present?
|
|
result = result.in_bucket(buckets.ids) if buckets.present?
|
|
result = result.tagged_with(tags.ids) if tags.present?
|
|
result = terms.reduce(result) do |result, term|
|
|
result.mentioning(term)
|
|
end
|
|
|
|
result
|
|
end
|
|
end
|
|
|
|
def cacheable?
|
|
buckets.exists?
|
|
end
|
|
|
|
def cache_key
|
|
ActiveSupport::Cache.expand_cache_key buckets.cache_key_with_version, super
|
|
end
|
|
end
|