aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/referential.rb26
1 files changed, 25 insertions, 1 deletions
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 0522d72c0..486c3c495 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -58,7 +58,13 @@ class Referential < ApplicationModel
belongs_to :referential_suite
- scope :ready, -> { where(ready: true) }
+ scope :pending, -> { where(ready: false, failed_at: nil, archived_at: nil, failed_at: nil) }
+ scope :ready, -> { where(ready: true, failed_at: nil, archived_at: nil) }
+ scope :failed, -> { where.not(failed_at: nil) }
+ scope :archived, -> { where.not(archived_at: nil) }
+
+ scope :ready, -> { where(ready: true, failed_at: nil, archived_at: nil) }
+ scope :ready, -> { where(ready: true, failed_at: nil, archived_at: nil) }
scope :in_periode, ->(periode) { where(id: referential_ids_in_periode(periode)) }
scope :include_metadatas_lines, ->(line_ids) { where('referential_metadata.line_ids && ARRAY[?]::bigint[]', line_ids) }
scope :order_by_validity_period, ->(dir) { joins(:metadatas).order("unnest(periodes) #{dir}") }
@@ -116,6 +122,24 @@ class Referential < ApplicationModel
@_models_with_checksum || []
end
+ def state
+ return :failed if failed_at.present?
+ return :archived if archived_at.present?
+ ready ? :ready : :pending
+ end
+
+ def failed!
+ update ready: false, failed_at: Time.now, archived_at: nil
+ end
+
+ def ready!
+ update ready: true, failed_at: nil, archived_at: nil
+ end
+
+ def archived!
+ update ready: true, failed_at: nil, archived_at: Time.now
+ end
+
def lines
if metadatas.blank?
workbench ? workbench.lines : associated_lines