Module: Prunable

Defined in:
lib/activerecord-prunable.rb

Constant Summary collapse

@@eager_load =
nil

Class Method Summary collapse

Class Method Details

.modelsObject



9
10
11
12
# File 'lib/activerecord-prunable.rb', line 9

def models
  @@eager_load ||= Rails.application.eager_load!
  ActiveRecord::Prunable.includes
end

.prune(*args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/activerecord-prunable.rb', line 22

def prune(*args)
  models, params = resolve_args(args)

  pruned = {}
  errors = []

  models.each do |model|
    begin
      pruned[model.table_name] = prune_model!(model, params)
    rescue StandardError => e
      errors << e
    end
  end

  [pruned, errors]
end

.prune!(*args) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/activerecord-prunable.rb', line 14

def prune!(*args)
  models, params = resolve_args(args)

  models.each_with_object({}) do |model, pruned|
    pruned[model.table_name] = prune_model!(model, params)
  end
end