Methods

Attributes

[R] entries

Class Public methods

new()

📝 Source code
# File activerecord/lib/active_record/message_pack.rb, line 48
      def initialize
        @entries = []
        @refs = {}.compare_by_identity
      end
🔎 See on GitHub

Instance Public methods

add_cached_associations(record, entry)

📝 Source code
# File activerecord/lib/active_record/message_pack.rb, line 81
      def add_cached_associations(record, entry)
        record.class.normalized_reflections.each_value do |reflection|
          if record.association_cached?(reflection.name) && record.association(reflection.name).loaded?
            entry << reflection.name << encode(record.association(reflection.name).target)
          end
        end
      end
🔎 See on GitHub

build_entry(record)

📝 Source code
# File activerecord/lib/active_record/message_pack.rb, line 73
      def build_entry(record)
        [
          ActiveSupport::MessagePack::Extensions.dump_class(record.class),
          record.attributes_for_database,
          record.new_record?
        ]
      end
🔎 See on GitHub

encode(input)

📝 Source code
# File activerecord/lib/active_record/message_pack.rb, line 53
      def encode(input)
        if input.is_a?(Array)
          input.map { |record| encode_record(record) }
        elsif input
          encode_record(input)
        end
      end
🔎 See on GitHub

encode_record(record)

📝 Source code
# File activerecord/lib/active_record/message_pack.rb, line 61
      def encode_record(record)
        ref = @refs[record]

        if !ref
          ref = @refs[record] = @entries.size
          @entries << build_entry(record)
          add_cached_associations(record, @entries.last)
        end

        ref
      end
🔎 See on GitHub