Class: ActiveAdmin::Exportable::Exporter::AssociationStruct

Inherits:
Object
  • Object
show all
Defined in:
lib/active_admin/exportable/exporter.rb

Instance Method Summary collapse

Constructor Details

#initialize(record:, association_name:, remove_ids:, next_level_includes: nil) ⇒ AssociationStruct

Returns a new instance of AssociationStruct.



112
113
114
115
116
117
# File 'lib/active_admin/exportable/exporter.rb', line 112

def initialize(record:, association_name:, remove_ids:, next_level_includes: nil)
  @next_level_includes = next_level_includes
  @reflection = record.association(association_name).reflection
  @association = record.send(association_name)
  @remove_ids = remove_ids
end

Instance Method Details

#dataObject



119
120
121
122
123
124
125
126
127
128
# File 'lib/active_admin/exportable/exporter.rb', line 119

def data
  {
    name: @reflection.name,
    inverse: @reflection.inverse_of&.name,
    foreign_key: @reflection.foreign_key,
    foreign_type: @reflection.foreign_type,
    kind: @reflection.class.name.match(/.*::(?<shortname>\w+)Reflection/)['shortname'].underscore,
    content: RootStruct.new(node: @association, includes: @next_level_includes, remove_ids: @remove_ids).data
  }.compact
end