Sha256: a144a5778c113ead2f641476f79fa890a93c1e289f4cfe37d8c270ff2d007ea6

Contents?: true

Size: 739 Bytes

Versions: 1

Compression:

Stored size: 739 Bytes

Contents

##
# Identificating 是身份关联,存储身份(identity)和访问者(visitor)之间的关联关系。

class Unidom::Visitor::Identificating < Unidom::Visitor::ApplicationRecord

  self.table_name = 'unidom_identificatings'

  include Unidom::Common::Concerns::ModelExtension

  belongs_to :identity, polymorphic: true
  belongs_to :visitor,  polymorphic: true

  scope :identity_is, ->(identity) { where identity: identity }
  scope :visitor_is,  ->(visitor)  { where visitor:  visitor  }

  def self.find_identity(visitor)
    visitor_is(visitor).first.try :identity
  end

  def self.identificate!(visitor, as: nil, at: Time.now)
    self.visitor_is(visitor).identity_is(as).valid_at.alive.first_or_create! opened_at: at
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unidom-visitor-1.12.3 app/models/unidom/visitor/identificating.rb