Sha256: 82a09d044344e90541adf6588afeff23ef3e32849ef35d47ccf73d9e1ed78f33

Contents?: true

Size: 1.07 KB

Versions: 15

Compression:

Stored size: 1.07 KB

Contents

module Deface
  module OriginalValidator

    def original_source
      return nil unless @args[:original].present?

      Deface::Parser.convert(@args[:original].clone)
    end

    # logs if original source has changed
    def validate_original(match)
      match = match.map(&:to_s).join if match.is_a? Array

      hashed_original = ::Digest::SHA1.hexdigest(match.to_s.gsub(/\s/, ''))

      if @args[:original].present?
        valid = @args[:original] == hashed_original

        unless valid
          valid = self.original_source.to_s.gsub(/\s/, '') == match.to_s.gsub(/\s/, '')
        end

        if !valid && defined?(Rails.logger)
          Rails.logger.error "\e[1;32mDeface: [ERROR]\e[0m The original source for '#{self.name}' has changed, this override should be reviewed to ensure it's still valid."
        end

        return valid
      else
        Rails.logger.info "\e[1;32mDeface: [WARNING]\e[0m No :original defined for '#{self.name}', you should change its definition to include:\n :original => '#{hashed_original}' "

        return nil
      end
    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
deface-1.9.0 lib/deface/original_validator.rb
deface-1.8.2 lib/deface/original_validator.rb
deface-1.8.1 lib/deface/original_validator.rb
deface-1.8.0 lib/deface/original_validator.rb
deface-1.7.0 lib/deface/original_validator.rb
deface-1.6.2 lib/deface/original_validator.rb
deface-1.6.1 lib/deface/original_validator.rb
deface-1.6.0 lib/deface/original_validator.rb
deface-1.5.3 lib/deface/original_validator.rb
deface-1.5.2 lib/deface/original_validator.rb
deface-1.5.1 lib/deface/original_validator.rb
deface-1.5.0 lib/deface/original_validator.rb
deface-1.4.0 lib/deface/original_validator.rb
deface-1.3.2 lib/deface/original_validator.rb
deface-1.3.1 lib/deface/original_validator.rb