Class: UserCustomAttribute

Inherits:
ApplicationRecord show all
Defined in:
app/models/user_custom_attribute.rb

Constant Summary

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Class Method Summary collapse

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.sessionsObject


25
26
27
28
29
30
31
# File 'app/models/user_custom_attribute.rb', line 25

def sessions
  return none if blocked_users.empty?

  arkose_sessions
    .by_user_id(blocked_users.map(&:user_id))
    .select(:value)
end

.upsert_custom_attributes(custom_attributes) ⇒ Object


15
16
17
18
19
20
21
22
23
# File 'app/models/user_custom_attribute.rb', line 15

def upsert_custom_attributes(custom_attributes)
  created_at = DateTime.now
  updated_at = DateTime.now

  custom_attributes.map! do |custom_attribute|
    custom_attribute.merge({ created_at: created_at, updated_at: updated_at })
  end
  upsert_all(custom_attributes, unique_by: [:user_id, :key])
end