# Pastebin AoO2nZwk require "ruby_tapas/data_mapper" require "ruby_tapas/email_verification_token" module RubyTapas class TokenMapper include DataMapper attr_accessor :email_gateway def table_name; :tokens; end def model_class; EmailVerificationToken; end def initialize( db = RubyTapas.db, email_gateway: RubyTapas.email_gateway, **options) super(db, options) @email_gateway = email_gateway end def process_associations(op) op.belongs_to(User, :user, :user_id, inverse_of: :email_verification_token) end def find_by_token_string(token_string, **options, &fallback) find_by_field_value(:token_string, token_string, **options, &fallback) end def find_by_user_id(user_id, **options, &fallback) find_by_field_value(:user_id, user_id, **options, &fallback) end def persisted_fields %i[created_at token_string redeemed sent] end def persistable_attributes(token) super.merge(user_id: token.user.id) end private def user_map @user_map ||= mapper_for_class(User) end end end