Sha256: 4097ae3e34bc787f8f7628e1eab2fe7274fe71cdba4b54de0f378b33547d0983

Contents?: true

Size: 603 Bytes

Versions: 9

Compression:

Stored size: 603 Bytes

Contents

# encoding: utf-8
module SexyValidations
  module Validators
    class Inclusion
      def self.validate(model, attribute, value, options)
        return unless value

        unless options.is_a?(Hash)
          options = {
            :within => options,
          }
        end
        
        data = case options[:within]
          when Proc
            options[:within].call(model)
          else
            options[:within]
        end

        unless data.include?(value)
          model.errors.add(attribute, options[:message] || "ungültige Auswahl")
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sexy_validations-0.5.4 lib/sexy_validations/validators/inclusion.rb
sexy_validations-0.5.3 lib/sexy_validations/validators/inclusion.rb
sexy_validations-0.5.2 lib/sexy_validations/validators/inclusion.rb
sexy_validations-0.5.1 lib/sexy_validations/validators/inclusion.rb
sexy_validations-0.5.0 lib/sexy_validations/validators/inclusion.rb
sexy_validations-0.4.3 lib/sexy_validations/validators/inclusion.rb
sexy_validations-0.4.2 lib/sexy_validations/validators/inclusion.rb
sexy_validations-0.4.1 lib/sexy_validations/validators/inclusion.rb
sexy_validations-0.4.0 lib/sexy_validations/validators/inclusion.rb