diff options
| author | Teddy Wing | 2018-05-14 18:42:59 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2018-05-14 18:42:59 +0200 | 
| commit | 72fd54c38b958d0be9d608a676e8fef84691d088 (patch) | |
| tree | 860870beb2a156cb45876e3c90726d21d5c5460a /app/models | |
| parent | 4ca91f7ccbb71013ffe869be8d7f5cf344d9917a (diff) | |
| download | chouette-core-72fd54c38b958d0be9d608a676e8fef84691d088.tar.bz2 | |
CleanUp: Add `#run_methods`
This method is coupled with a new virtual attribute that can be used in
the initializer like:
    CleanUp.new(methods: [:destroy_routes])
The method will run all methods specified in the `:methods` list. The
plan is to replace the calls to `destroy_routes` etc. with a call to
this method. The result will be a more configurable clean-up process,
allowing users to selectively choose what to clean up by declaring what
methods in the `CleanUp` model to call.
Refs #6854
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/clean_up.rb | 8 | 
1 files changed, 8 insertions, 0 deletions
| diff --git a/app/models/clean_up.rb b/app/models/clean_up.rb index f668b9fda..4656cdb31 100644 --- a/app/models/clean_up.rb +++ b/app/models/clean_up.rb @@ -16,6 +16,8 @@ class CleanUp < ApplicationModel      where(referential_id: referential.id)    end +  attr_accessor :methods +    def end_date_must_be_greater_that_begin_date      if self.end_date && self.date_type == 'between' && self.begin_date >= self.end_date        errors.add(:base, I18n.t('activerecord.errors.models.clean_up.invalid_period')) @@ -54,6 +56,12 @@ class CleanUp < ApplicationModel      end    end +  def run_methods +    return if methods.nil? + +    methods.each { |method| send(method) } +  end +    def destroy_time_tables_between      time_tables = Chouette::TimeTable.where('end_date < ? AND start_date > ?', self.end_date, self.begin_date)      self.destroy_time_tables(time_tables) | 
