Module: ActiveArchiver::ActiveRecordExt
- Defined in:
- lib/active_archiver/active_record_ext.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #archive(includes: [], basename: ["", ".json"], dir: Dir.tmpdir) ⇒ Object
- #export(includes: []) ⇒ Object
Class Method Details
.included(model) ⇒ Object
4 5 6 |
# File 'lib/active_archiver/active_record_ext.rb', line 4 def self.included(model) model.extend ClassMethods end |
Instance Method Details
#archive(includes: [], basename: ["", ".json"], dir: Dir.tmpdir) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/active_archiver/active_record_ext.rb', line 18 def archive(includes: [], basename: ["", ".json"], dir: Dir.tmpdir) Tempfile.open(basename, dir) do |fp| fp.puts export(includes: includes).to_json fp end end |
#export(includes: []) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/active_archiver/active_record_ext.rb', line 8 def export(includes: []) CarrierWave::Uploader::Base.active_archiver_blob_data = true hash = {} hash[:attributes] = self.serializable_hash hash[:associations] = [] hash = recursive_export(hash, self, includes) CarrierWave::Uploader::Base.active_archiver_blob_data = false hash end |