Sha256: 1dcdae5af0f83bd70bb1a3a99e954fc4aea917661cca82bfe2fb8b0c4728cd4a

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

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  }

  ##
  # 根据访问者 visitor ,找到其对应的登录身份标示 identity (如手机号码或自定义用户名)。如:
  # mobile_phone_number = Unidom::Visitor::Identificating.find_identity user
  # puts mobile_phone_number.phone_number
  def self.find_identity(visitor)
    visitor_is(visitor).first.try :identity
  end

  ##
  # 将访问者 visitor 和参与者 party 进行身份关联。关联时间是 at ,缺省为当前时间。如:
  # Unidom::Visitor::Identificating.identificate! user, as: email
  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 unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Visitor::Identificating'

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
unidom-visitor-2.0 app/models/unidom/visitor/identificating.rb
unidom-visitor-1.13.10 app/models/unidom/visitor/identificating.rb
unidom-visitor-1.13.9 app/models/unidom/visitor/identificating.rb
unidom-visitor-1.13.8 app/models/unidom/visitor/identificating.rb
unidom-visitor-1.13.7 app/models/unidom/visitor/identificating.rb
unidom-visitor-1.13.6 app/models/unidom/visitor/identificating.rb
unidom-visitor-1.13.5 app/models/unidom/visitor/identificating.rb