Class: Unidom::Visitor::Recognization

Inherits:
ApplicationRecord show all
Includes:
Common::Concerns::ModelExtension
Defined in:
app/models/unidom/visitor/recognization.rb

Overview

Recognization 是访问者识别,用于维护访问者和参与者的对应关系。

Class Method Summary collapse

Class Method Details

.cognize!(visitor, as: nil, at: Time.now, primary: false) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/unidom/visitor/recognization.rb', line 19

def self.cognize!(visitor, as: nil, at: Time.now, primary: false)
  query = visitor_is(visitor).party_is(as).valid_at.alive
  recognization = query.first
  if recognization.present?
    recognization.elemental = primary
    recognization.save!
    recognization
  else
    query.create! elemental: primary, opened_at: at
  end
end