Module: ActiveRecord::Tenanted::MessagePack::Decoder

Defined in:
lib/active_record/tenanted/message_pack.rb

Overview

This patch sees every record in a payload, unlike the Marshal, YAML, and JSON hooks, which are methods on the record and so only ever run for tenanted models.

Instance Method Summary collapse

Instance Method Details

#build_record(entry) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/active_record/tenanted/message_pack.rb', line 9

def build_record(entry)
  class_name, attributes_hash, * = entry

  if ActiveSupport::MessagePack::Extensions.load_class(class_name).tenanted?
    has_tenant = attributes_hash.key?("tenant")
    tenant_name = attributes_hash.delete("tenant")

    super.tap do |record|
      record.instance_variable_set(:@tenant, tenant_name) if has_tenant
    end
  else
    super
  end
end