Sha256: e7fde49d9afea4df03c9d07cbaeb2d39ad27855c1cb2369b8b60c1659173374e
Contents?: true
Size: 852 Bytes
Versions: 1
Compression:
Stored size: 852 Bytes
Contents
module ActiveRecord module MySQL module Strict class Validation < Struct.new(:model, :field) # Inject validations into an ActiveRecord model def self.inject_validations(model, options = {}) except = options[:except] || [] model_columns = model.columns.dup.reject { |c| except.include?(c.name.to_sym) } if only = options[:only] model_columns = model_columns.select { |c| only.include?(c.name.to_sym) } end model_columns.each do |field| validation = "#{field.type.to_s.camelize}Validation" if ActiveRecord::MySQL::Strict::Validation.const_defined?(validation) "ActiveRecord::MySQL::Strict::Validation::#{validation}".constantize.new(model, field).apply end end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activerecord_mysql_strict-0.2.1 | lib/active_record/mysql/strict/validation.rb |