Sha256: caa7bf6d8016e2fa203fd1eac6da459ffecec305a5a13d0ee8047ce770dca697
Contents?: true
Size: 1.93 KB
Versions: 4
Compression:
Stored size: 1.93 KB
Contents
require 'validates_timeliness/formats' require 'validates_timeliness/parser' require 'validates_timeliness/validator' require 'validates_timeliness/validation_methods' require 'validates_timeliness/active_record/attribute_methods' require 'validates_timeliness/active_record/multiparameter_attributes' require 'validates_timeliness/action_view/instance_tag' begin i18n_path = $:.grep(/active_support\/vendor\/i18n-/) if i18n_path.empty? require 'i18n/version' else require i18n_path[0] + '/version' end rescue LoadError end if defined?(I18n) module ValidatesTimeliness mattr_accessor :default_timezone self.default_timezone = :utc mattr_accessor :use_time_zones self.use_time_zones = false I18N_LATEST = defined?(I18n::VERSION) && I18n::VERSION >= '0.4.0' locale_file = I18N_LATEST ? 'en.new.yml' : 'en.old.yml' LOCALE_PATH = File.expand_path(File.join(File.dirname(__FILE__),'validates_timeliness','locale',locale_file)) class << self def enable_datetime_select_extension! enable_datetime_select_invalid_value_extension! enable_multiparameter_attributes_extension! end def load_error_messages defaults = YAML::load(IO.read(LOCALE_PATH))['en'] ValidatesTimeliness::Validator.error_value_formats = defaults['validates_timeliness']['error_value_formats'].symbolize_keys if defined?(I18n) I18n.load_path.unshift(LOCALE_PATH) I18n.reload! else errors = defaults['activerecord']['errors']['messages'].inject({}) {|h,(k,v)| h[k.to_sym] = v.gsub(/\{\{\w*\}\}/, '%s');h } ::ActiveRecord::Errors.default_error_messages.update(errors) end end def setup_for_rails self.default_timezone = ::ActiveRecord::Base.default_timezone self.use_time_zones = ::ActiveRecord::Base.time_zone_aware_attributes rescue false self.enable_active_record_datetime_parser! load_error_messages end end end ValidatesTimeliness.setup_for_rails
Version data entries
4 entries across 4 versions & 2 rubygems