Module: ActiveModelArchive::Restore::ClassMethods
- Defined in:
- lib/active_model_archive/restore.rb
Instance Method Summary collapse
- #each_archive(io) ⇒ Object
- #each_instance(io) ⇒ Object
- #each_record(io) ⇒ Object
- #restore!(io, options = {}) ⇒ Object
Instance Method Details
#each_archive(io) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/active_model_archive/restore.rb', line 27 def each_archive(io) count = 0 archiver.parse(io) do |hash| count += 1 yield hash end count end |
#each_instance(io) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/active_model_archive/restore.rb', line 13 def each_instance(io) each_archive(io) do |hash| attributes = {} archive_attributes.each { |key| attributes[key] = hash[key] } yield new(attributes) end end |
#each_record(io) ⇒ Object
21 22 23 24 25 |
# File 'lib/active_model_archive/restore.rb', line 21 def each_record(io) each_archive(io) do |hash| yield find(hash['id']) end end |
#restore!(io, options = {}) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/active_model_archive/restore.rb', line 6 def restore!(io, ={}) each_instance(io) do |object| object.save(validate: !![:validate]) yield object if block_given? end end |