Class: HashPivot::Repository::ActiveRecordRepository

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/hash_pivot/repository/active_record_repository.rb

Instance Method Summary collapse

Methods included from Base

#hash_by_group, included, #initialize

Instance Method Details

#translate_data(data) ⇒ Object

Parameters:

  • data (ActiveRecord::Relation)


10
11
12
13
14
15
16
17
# File 'lib/hash_pivot/repository/active_record_repository.rb', line 10

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