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



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

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



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

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



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

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

#run!Object



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

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



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

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