Skip to content

Instantly share code, notes, and snippets.

@rmascarenhas
Created September 19, 2012 19:57
Show Gist options
  • Save rmascarenhas/3751867 to your computer and use it in GitHub Desktop.
Save rmascarenhas/3751867 to your computer and use it in GitHub Desktop.
delivery strategy
class TagSubscription < ActiveRecord::Base
belongs_to :delivery_strategy
end
class DeliveryStrategy < ActiveRecord::Base
# Attributes:
# type: can be 'real_time', 'daily' or 'weekly'
# day: contain the day of the week
# time: the time of the day (morning, afternoon, night)
#
has_many :tag_subscriptions
end
# Find immediate deliveries
DeliveryStrategy.where(:type => :real_time)
# Find daily deliveries of the morning
DeliveryStrategy.where(:type => :daily, :time => :morning)
# Weekly subscriptions to be delivered every Tuesday night
DeliveryStrategy.where(:type => :weekly, :day => :tuesday, :time => :night)
@fabioyamate
Copy link

I'm ok with it, I was thinking if DeliveryStrategy needed to be an AR, but I agree with it...

If for some reason we get more types of subscriptions, we can easily port to a polymorphic version..

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment