Sha256: 92852d6a2c62d54497dd827704a68585847fa36f88a202acb8cb1909465e891c

Contents?: true

Size: 1.01 KB

Versions: 8

Compression:

Stored size: 1.01 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)
      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

8 entries across 8 versions & 1 rubygems

Version Path
deface-1.0.0 lib/deface/original_validator.rb
deface-1.0.0.rc4 lib/deface/original_validator.rb
deface-1.0.0.rc3 lib/deface/original_validator.rb
deface-1.0.0.rc2 lib/deface/original_validator.rb
deface-1.0.0.rc1 lib/deface/original_validator.rb
deface-0.9.1 lib/deface/original_validator.rb
deface-0.9.0 lib/deface/original_validator.rb
deface-0.8.0 lib/deface/original_validator.rb