Class: BulkAction

Inherits:
ApplicationRecord show all
Defined in:
app/models/bulk_action.rb

Overview

BulkAction

Instance Method Summary collapse

Instance Method Details

#check_run_stateObject



42
43
44
45
46
47
# File 'app/models/bulk_action.rb', line 42

def check_run_state
  nil if state_machine.current_state == "complete"

  # @TODO / background job for collecting documents
  # state_machine.transition_to!(:complete) if documents.in_state(:queued).blank?
end

#collect_documentsObject



54
55
56
57
58
59
60
61
62
# File 'app/models/bulk_action.rb', line 54

def collect_documents
  cgi = CGI.unescape(scope)
  uri = URI.parse(cgi)
  if uri.path.include?("fetch")
    fetch_documents(uri)
  else
    api_documents(uri)
  end
end

#revert!Object



49
50
51
52
# File 'app/models/bulk_action.rb', line 49

def revert!
  # Queue Revert Job
  BulkActionRevertJob.perform_later(self)
end

#run!Object



31
32
33
34
35
36
37
38
39
40
# File 'app/models/bulk_action.rb', line 31

def run!
  # @TODO: guard this call for validation?

  # Queue Job
  BulkActionRunJob.perform_later(self)

  # Capture State
  # state_machine.transition_to!(:imported)
  # save
end

#state_machineObject



27
28
29
# File 'app/models/bulk_action.rb', line 27

def state_machine
  @state_machine ||= BulkActionStateMachine.new(self, transition_class: BulkActionTransition)
end