Sha256: 74e6ba4f7fee7d2ec8df2e1bb73c22954704f25fb78350bd9210afde11ee81b5

Contents?: true

Size: 810 Bytes

Versions: 4

Compression:

Stored size: 810 Bytes

Contents

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

class Unidom::Visitor::Recognization < ActiveRecord::Base

  self.table_name = 'unidom_recognizations'

  belongs_to :visitor, polymorphic: true
  belongs_to :party,   polymorphic: true

  scope :visitor_is,  ->(visitor) { where visitor: visitor }
  scope :party_is,    ->(party)   { where party:   party   }

  include Unidom::Common::Concerns::ModelExtension

  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

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
unidom-visitor-1.3 app/models/unidom/visitor/recognization.rb
unidom-visitor-1.2 app/models/unidom/visitor/recognization.rb
unidom-visitor-1.1 app/models/unidom/visitor/recognization.rb
unidom-visitor-1.0 app/models/unidom/visitor/recognization.rb