aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/referential.rb
diff options
context:
space:
mode:
authorZog2018-04-18 09:24:08 +0200
committerJohan Van Ryseghem2018-04-27 11:17:19 +0200
commit681f874e3150c35b03e74b25827b74791ae9ae95 (patch)
tree5a0cb5c7ab520ec2b8471f95287f89724a469851 /app/models/referential.rb
parent9279fbf0cc56e0e793de2a17547da9465ae83997 (diff)
downloadchouette-core-681f874e3150c35b03e74b25827b74791ae9ae95.tar.bz2
Refs #6572; Define 4 different states on Referentials
With according methods and scopes
Diffstat (limited to 'app/models/referential.rb')
-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