Class: ActiveAdmin::Exportable::Exporter
- Inherits:
-
Object
- Object
- ActiveAdmin::Exportable::Exporter
show all
- Defined in:
- lib/active_admin/exportable/exporter.rb
Defined Under Namespace
Classes: AssociationStruct, RootStruct
Instance Method Summary
collapse
Constructor Details
#initialize(record, includes: [], remove_ids: false) ⇒ Exporter
TODO: extract this to other gem.
7
8
9
10
11
12
13
|
# File 'lib/active_admin/exportable/exporter.rb', line 7
def initialize(record, includes: [], remove_ids: false)
unless record.is_a?(ActiveRecord::Relation) || record.is_a?(ActiveRecord::Base)
raise ArgumentError, 'You need provide an ActiveRecord record as argument.'
end
@root = RootStruct.new(node: record, includes: includes, remove_ids: remove_ids)
end
|
Instance Method Details
#export ⇒ Object
15
16
17
|
# File 'lib/active_admin/exportable/exporter.rb', line 15
def export
@root.data
end
|
#to_file(path:) ⇒ Object
19
20
21
|
# File 'lib/active_admin/exportable/exporter.rb', line 19
def to_file(path:)
File.open(path, 'w') { |f| f.write to_json }
end
|
#to_json(*_args) ⇒ Object
23
24
25
|
# File 'lib/active_admin/exportable/exporter.rb', line 23
def to_json(*_args)
export.to_json
end
|