Sha256: cc7305b9588e00febb56188ba4e990fb5187314f113bf3fa0061dc27df7ae1a6

Contents?: true

Size: 898 Bytes

Versions: 68

Compression:

Stored size: 898 Bytes

Contents

module ActiveModel
  module Validations
    class FileReadabilityValidator < ::ActiveModel::EachValidator
      def validate_each(record, attribute, value)
        filename = File.expand_path(value) if !value.nil? && value.respond_to?(:to_s)
        if filename.nil?
          record.errors.add(attribute, options[:message] || :filename_is_nil)
          return
        end
        unless File.exists?(filename)
          record.errors.add(attribute, options[:message] || :file_not_existent, filename: filename)
          return
        end
        unless File.file?(filename)
          record.errors.add(attribute, options[:message] || :file_not_file, filename: filename)
          return
        end
        unless File.readable?(filename)
          record.errors.add(attribute, options[:message] || :file_not_readable, filename: filename)
          return
        end
      end
    end
  end
end

Version data entries

68 entries across 68 versions & 2 rubygems

Version Path
cmor_rbac-0.0.60.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.59.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.58.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.57.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.56.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.55.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.54.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.53.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.52.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.51.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.50.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.49.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.48.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.45.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.44.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.43.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.42.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.41.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.40.pre lib/active_model/validations/file_readability_validator.rb
cmor_rbac-0.0.39.pre lib/active_model/validations/file_readability_validator.rb