Sha256: 5cce7a2e93fe9ce5aa5fdd473285c5ee6bf0cc24d9fe9430a3bbf8d0a1659957

Contents?: true

Size: 830 Bytes

Versions: 1

Compression:

Stored size: 830 Bytes

Contents

module MList
  module Manager
    
    class Database
      def create_list(address, attributes = {})
        attributes = {
          :address => address,
          :label   => address.match(/\A(.*?)@/)[1]
        }.merge(attributes)
        List.create!(attributes)
      end
      
      def lists(email)
        lists = List.find_all_by_address(email.list_addresses)
        email.list_addresses.map { |a| lists.detect {|l| l.address == a} }
      end
      
      class List < ActiveRecord::Base
        include ::MList::List
        
        has_many :subscriptions, :dependent => :delete_all
        
        def subscribe(address)
          subscriptions.find_or_create_by_address(address)
        end
      end
      
      class Subscription < ActiveRecord::Base
        belongs_to :list
      end
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aiwilliams-mlist-0.0.0 lib/mlist/manager/database.rb