Sha256: c495e2568a54f40bf7a644f583924f0cdfc0ace46ff2d8ff6099787db4473dea
Contents?: true
Size: 852 Bytes
Versions: 1
Compression:
Stored size: 852 Bytes
Contents
require 'set' module OptOut module Adapters # Adapter that stores persists data in memory in a hash. # # Options # :store - optional Hash instance to store unsubscriptions class MemoryAdapter < AbstractAdapter # Subscribe `user_id` to `list_id`. Returns nothing. def subscribe(list_id, user_id) store[list_id].delete(user_id) and return end def unsubscribe(list_id, user_id) store[list_id] ||= Set.new store[list_id] << user_id nil end def unsubscribed?(list_id, user_id) (store[list_id] || []).include?(user_id) end def unsubscribers(list_id) store[list_id].to_a end def reset store.clear end private def store @store ||= @options[:store] || Hash.new end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
opt_out-1.0.0 | lib/opt_out/adapters/memory_adapter.rb |