Sha256: 6f678e876031a607c61cfc7a45a0a2beab1adf64ca351fa01deee457322a7a4c

Contents?: true

Size: 545 Bytes

Versions: 4

Compression:

Stored size: 545 Bytes

Contents

# frozen_string_literal: true

require_relative './base'

module HashPivot
  module Repository
    class ActiveRecordRepository
      include HashPivot::Repository::Base
      # @param [ActiveRecord::Relation] data
      def translate_data(data)
        attribute_names = data.model.attribute_names
        data.pluck(*attribute_names).map do |r|
          attribute_names.each_with_object({}).with_index do |(attribute_name, memo), index|
            memo[attribute_name.to_sym] = r[index]
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hash_pivot-0.3.1 lib/hash_pivot/repository/active_record_repository.rb
hash_pivot-0.3.0 lib/hash_pivot/repository/active_record_repository.rb
hash_pivot-0.2.0 lib/hash_pivot/repository/active_record_repository.rb
hash_pivot-0.1.0 lib/hash_pivot/repository/active_record_repository.rb