Files
fizzy/app/models/card/entropic.rb
T
2025-09-24 16:22:42 +02:00

38 lines
1.2 KiB
Ruby

module Card::Entropic
extend ActiveSupport::Concern
included do
scope :due_to_be_postponed, -> do
active
.left_outer_joins(collection: :entropy_configuration)
.where("last_active_at <= DATETIME('now', '-' || COALESCE(entropy_configurations.auto_postpone_period, ?) || ' seconds')",
Entropy::Configuration.default.auto_postpone_period)
end
scope :postponing_soon, -> do
active
.left_outer_joins(collection: :entropy_configuration)
.where("last_active_at > DATETIME('now', '-' || COALESCE(entropy_configurations.auto_postpone_period, ?) || ' seconds')", Entropy::Configuration.default.auto_postpone_period)
.where("last_active_at <= DATETIME('now', '-' || CAST(COALESCE(entropy_configurations.auto_postpone_period, ?) * 0.75 AS INTEGER) || ' seconds')", Entropy::Configuration.default.auto_postpone_period)
end
delegate :auto_postpone_period, to: :collection
end
class_methods do
def auto_postpone_all_due
due_to_be_postponed.find_each do |card|
card.postpone
end
end
end
def entropy
Card::Entropy.for(self)
end
def entropic?
entropy.present?
end
end