Class: ArchiveHook::ScopeRestorer
- Inherits:
-
Object
- Object
- ArchiveHook::ScopeRestorer
- Defined in:
- lib/archive_hook.rb
Instance Method Summary collapse
- #call(scope) ⇒ Object
-
#initialize(dependencies: {}) ⇒ ScopeRestorer
constructor
A new instance of ScopeRestorer.
Constructor Details
#initialize(dependencies: {}) ⇒ ScopeRestorer
Returns a new instance of ScopeRestorer.
50 51 52 |
# File 'lib/archive_hook.rb', line 50 def initialize(dependencies: {}) @dependencies = dependencies end |
Instance Method Details
#call(scope) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/archive_hook.rb', line 54 def call(scope) parent = scope.model table_name = "#{scope.table_name}_archive as #{scope.table_name}" parent_id_groups = scope.from(table_name).in_batches.map { |relation| relation.pluck(:id) } parent_id_groups.each do |parent_ids| restore_by_ids(parent, parent_ids) end restore_children(parent, parent_id_groups) end |