# frozen_string_literal: true module Maquina module Blockeable extend ActiveSupport::Concern included do if has_attribute?(:blocked_at) && has_attribute?(:temporary_blocked_at) define_method(:blocked?) do temporary_blocked_until = nil if Maquina.configuration.temporary_block.present? && temporary_blocked_at.present? temporary_blocked_until = temporary_blocked_at.since(Maquina.configuration.temporary_block) end blocked_at.present? || (temporary_blocked_until.present? && temporary_blocked_until > Time.zone.now) end scope :unblocked, -> { where(blocked_at: nil).where("(coalesce(temporary_blocked_at + interval '? minutes', now())) <= now()", Maquina.configuration.temporary_block&.in_minutes&.to_i || 0) } elsif has_attribute(:blocked_at) define_method(:blocked?) do blocked_at.present? end scope :unblocked, -> { where(blocked_at: nil) } end end end end