Sha256: 3e10ccdd227bc453b617aed012f8dd3d812f4a262914d58f5280f6351705de48

Contents?: true

Size: 660 Bytes

Versions: 1

Compression:

Stored size: 660 Bytes

Contents

module Mailkick
  module Model
    def has_subscriptions
      class_eval do
        has_many :mailkick_subscriptions, class_name: "Mailkick::Subscription", as: :subscriber
        scope :subscribed, ->(list) { joins(:mailkick_subscriptions).where(mailkick_subscriptions: {list: list}) }

        def subscribe(list)
          mailkick_subscriptions.where(list: list).first_or_create!
          nil
        end

        def unsubscribe(list)
          mailkick_subscriptions.where(list: list).delete_all
          nil
        end

        def subscribed?(list)
          mailkick_subscriptions.where(list: list).exists?
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mailkick-1.3.1 lib/mailkick/model.rb