1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-23 23:29:39 +02:00
Maybe/app/models/rule.rb

31 lines
612 B
Ruby
Raw Normal View History

2025-02-25 11:34:37 -05:00
class Rule < ApplicationRecord
RESOURCE_TYPES = %w[transaction].freeze
2025-02-25 11:34:37 -05:00
belongs_to :family
has_many :conditions, dependent: :destroy
2025-02-25 11:34:37 -05:00
has_many :actions, dependent: :destroy
validates :effective_date, presence: true
validates :resource_type, inclusion: { in: RESOURCE_TYPES }
def apply
scope = resource_scope
conditions.each do |condition|
scope = condition.apply(scope)
end
actions.each do |action|
action.apply(scope)
end
end
private
def resource_scope
case resource_type
when "transaction"
family.transactions
end
end
2025-02-25 11:34:37 -05:00
end