diff options
| author | Zog | 2018-01-17 16:57:59 +0100 | 
|---|---|---|
| committer | Zog | 2018-01-17 16:57:59 +0100 | 
| commit | b853120644819dd1ae646ea762f457836abfea09 (patch) | |
| tree | 29770024a36dfc9b9e697e014ddc25c0b7b32a68 /app/models | |
| parent | e36dcdd912b28eb69fa14ee7c830d717b9c9300a (diff) | |
| download | chouette-core-b853120644819dd1ae646ea762f457836abfea09.tar.bz2 | |
Refs #5593 @1h;
- Register all models that implement checksums
- Add a simple rake task that updates all checksums within a given
referential
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/concerns/checksum_support.rb | 1 | ||||
| -rw-r--r-- | app/models/referential.rb | 40 | 
2 files changed, 41 insertions, 0 deletions
| diff --git a/app/models/concerns/checksum_support.rb b/app/models/concerns/checksum_support.rb index b700ef286..ff73c87a3 100644 --- a/app/models/concerns/checksum_support.rb +++ b/app/models/concerns/checksum_support.rb @@ -5,6 +5,7 @@ module ChecksumSupport    included do      before_save :set_current_checksum_source, :update_checksum +    Referential.register_model_with_checksum self    end    def checksum_attributes diff --git a/app/models/referential.rb b/app/models/referential.rb index 92931564d..baaa354da 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -75,6 +75,46 @@ class Referential < ActiveRecord::Base    alias_method_chain :save, :table_lock_timeout +  if Rails.env.development? +    def self.force_register_models_with_checksum +      paths = Rails.application.paths['app/models'].to_a +      Rails.application.railties.each do |tie| +        next unless tie.respond_to? :paths +        paths += tie.paths['app/models'].to_a +      end + +      paths.each do |path| +        next unless File.directory?(path) +        Dir.chdir path do +          Dir['**/*.rb'].each do |src| +            next if src =~ /^concerns/ +            # thanks for inconsistent naming ... +            if src == "route_control/zdl_stop_area.rb" +              RouteControl::ZDLStopArea +              next +            end +            Rails.logger.info "Loading #{src}" +            begin +              src[0..-4].classify.safe_constantize +            rescue => e +              Rails.logger.info "Failed: #{e.message}" +              nil +            end +          end +        end +      end +    end +  end + +  def self.register_model_with_checksum klass +    @_models_with_checksum ||= [] +    @_models_with_checksum << klass +  end + +  def self.models_with_checksum +    @_models_with_checksum || [] +  end +    def lines      if metadatas.blank?        workbench ? workbench.lines : associated_lines | 
