Class: EAction

Inherits:
Object
  • Object
show all
Includes:
NdrWorkflow::EActionProgress
Defined in:
app/models/e_action.rb

Overview

EAction table.

Constant Summary

Constants included from NdrWorkflow::EActionProgress

NdrWorkflow::EActionProgress::COMMENT_CLASSES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NdrWorkflow::EActionProgress

#log_error, #progress, #update_percentage

Class Method Details

.make_and_save!(e_batchid, actiontype, started, finished, userid, status = nil) ⇒ Object

A quick and simple way to create a single EAction.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'app/models/e_action.rb', line 101

def self.make_and_save!(e_batchid, actiontype, started, finished, userid, status = nil)
  a = create(
    e_batchid: e_batchid,
    e_actiontype: actiontype,
    started: started,
    finished: finished,
    startedby: userid,
    status: status
  )
  if a.errors.to_a.blank?
    a
  else
    raise and return a.errors
  end
end

Instance Method Details

#ensure_action_not_in_futureObject

rdoc validation started or finished cannot be in the future



82
83
84
85
86
87
88
# File 'app/models/e_action.rb', line 82

def ensure_action_not_in_future
  unless finished.blank? || started.blank?
    if started > Time.now || finished > Time.now
      errors.add(:e_action, 'action can not be in the future.')
    end
  end
end

#ensure_actiontype_not_nilObject

rdoc validation e_actiontype cannot be nil.



35
36
37
# File 'app/models/e_action.rb', line 35

def ensure_actiontype_not_nil
  errors.add(:e_action, 'e_actiontype can not be nil.') if e_actiontype.blank?
end

#ensure_batch_not_nilObject

rdoc validation batch cannot be nil.



67
68
69
# File 'app/models/e_action.rb', line 67

def ensure_batch_not_nil
  errors.add(:e_action, 'does not belong to any batch.') if e_batch.nil?
end

#ensure_batchid_not_nilObject

rdoc validation e_batchid cannot be nil.



61
62
63
# File 'app/models/e_action.rb', line 61

def ensure_batchid_not_nil
  errors.add(:e_action, 'e_batchid cannot be nil.') if e_batchid.blank?
end

#ensure_started_not_after_finishedObject

rdoc validation started must not be after finished



92
93
94
95
96
97
98
# File 'app/models/e_action.rb', line 92

def ensure_started_not_after_finished
  unless finished.blank? || started.blank?
    if started > finished
      errors.add(:e_action, 'action can not be finished before it started.')
    end
  end
end

#ensure_started_not_nilObject

rdoc validation started cannot be nil.



73
74
75
76
77
78
# File 'app/models/e_action.rb', line 73

def ensure_started_not_nil
  if started.blank?
    errors.add(:e_action, 'does not have a start time.')
    return
  end
end

#ensure_startedby_not_nilObject

rdoc validation startedby user cannot be nil.



48
49
50
# File 'app/models/e_action.rb', line 48

def ensure_startedby_not_nil
  errors.add(:e_action, 'user can not be nil.') if startedby.blank?
end

#ensure_timestamp_consistencyObject



27
28
29
30
31
# File 'app/models/e_action.rb', line 27

def ensure_timestamp_consistency
  if started_changed? && (e_batch.e_actions.collect(&:finished).compact.max || started) > started then
    raise RuntimeError, "EBatch already has an action with a timestamp greater than #{started} - Possible clock drift or other inconsitency"
  end
end

#ensure_valid_actiontypeObject

rdoc validation e_actiontype must exist in our lookup table.



41
42
43
44
# File 'app/models/e_action.rb', line 41

def ensure_valid_actiontype
  return if ZeActiontype.valid_value?(e_actiontype)
  errors.add(:e_action, 'e_actiontype does not exist.')
end

#ensure_valid_startedbyObject

rdoc validation startedby user must exist in our lookup table.



54
55
56
57
# File 'app/models/e_action.rb', line 54

def ensure_valid_startedby
  return if Zuser.valid_value?(startedby)
  errors.add(:e_action, 'user does not exist.')
end