Sha256: 622c94235eceac778a266167406fc74a5e5f11f7f62aa25019aee79058b061d6

Contents?: true

Size: 810 Bytes

Versions: 8

Compression:

Stored size: 810 Bytes

Contents

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

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

  self.table_name = 'unidom_recognizations'

  include Unidom::Common::Concerns::ModelExtension

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

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

  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

8 entries across 8 versions & 1 rubygems

Version Path
unidom-visitor-1.11 app/models/unidom/visitor/recognization.rb
unidom-visitor-1.10 app/models/unidom/visitor/recognization.rb
unidom-visitor-1.9 app/models/unidom/visitor/recognization.rb
unidom-visitor-1.8 app/models/unidom/visitor/recognization.rb
unidom-visitor-1.7 app/models/unidom/visitor/recognization.rb
unidom-visitor-1.6 app/models/unidom/visitor/recognization.rb
unidom-visitor-1.5 app/models/unidom/visitor/recognization.rb
unidom-visitor-1.4 app/models/unidom/visitor/recognization.rb