Module: ActiverecordWithProgress::ActiverecordRelation

Defined in:
lib/activerecord_with_progress/activerecord_relation.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Adds a progress bar to iterator methods if _with_progress or _and_progress is appended to the method name. Arguments are passed through to the backing method, with options pulled from the last Hash in the argument list (if any). If only our own options are specified, the options hash will be deleted from the argument list (so no arguments will be passed to methods that expect no arguments, like #each).

Options:

:handle_errors - If true, returns two values: the original result and a
                 Hash mapping records to errors.
:total - Override the total count used by the progress bar.


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/activerecord_with_progress/activerecord_relation.rb', line 16

def method_missing(method, *args)
  name = method.to_s
  if name.end_with?('_with_progress') || name.end_with?('_and_progress')
    name = name.sub(/_(with|and)_progress$/, '')
    iterate_with_progress(name, *args) do |*a|
      yield *a
    end
  else
    super
  end
end