Module: ValidatesTimeliness

Defined in:
lib/validates_timeliness.rb,
lib/validates_timeliness/formats.rb,
lib/validates_timeliness/validator.rb,
lib/validates_timeliness/core_ext/date.rb,
lib/validates_timeliness/core_ext/time.rb,
lib/validates_timeliness/core_ext/date_time.rb,
lib/validates_timeliness/validation_methods.rb,
lib/validates_timeliness/action_view/instance_tag.rb,
lib/validates_timeliness/active_record/attribute_methods.rb,
lib/validates_timeliness/active_record/multiparameter_attributes.rb

Defined Under Namespace

Modules: ActionView, ActiveRecord, CoreExtensions, ValidationMethods Classes: Formats, Validator

Constant Summary collapse

LOCALE_PATH =
File.expand_path(File.dirname(__FILE__) + '/validates_timeliness/locale/en.yml')

Class Method Summary collapse

Class Method Details

.default_error_messagesObject



34
35
36
37
38
39
40
# File 'lib/validates_timeliness.rb', line 34

def default_error_messages
  if Rails::VERSION::STRING < '2.2'
    ::ActiveRecord::Errors.default_error_messages
  else
    I18n.translate('activerecord.errors.messages')
  end
end

.load_error_messages_with_i18nObject



24
25
26
# File 'lib/validates_timeliness.rb', line 24

def load_error_messages_with_i18n
  I18n.load_path += [ LOCALE_PATH ]
end

.load_error_messages_without_i18nObject



28
29
30
31
32
# File 'lib/validates_timeliness.rb', line 28

def load_error_messages_without_i18n
  messages = YAML::load(IO.read(LOCALE_PATH))
  errors = messages['en']['activerecord']['errors']['messages'].inject({}) {|h,(k,v)| h[k.to_sym] = v.gsub(/\{\{\w*\}\}/, '%s');h }
  ::ActiveRecord::Errors.default_error_messages.update(errors)
end

.setup_for_railsObject



54
55
56
57
58
59
60
# File 'lib/validates_timeliness.rb', line 54

def setup_for_rails
  major, minor = Rails::VERSION::MAJOR, Rails::VERSION::MINOR
  self.default_timezone = ::ActiveRecord::Base.default_timezone
  self.send("setup_for_rails_#{major}_#{minor}")
rescue
  puts "Rails version #{major}.#{minor}.x not explicitly supported by validates_timeliness plugin. You may encounter some problems."
end

.setup_for_rails_2_0Object



42
43
44
# File 'lib/validates_timeliness.rb', line 42

def setup_for_rails_2_0
  load_error_messages_without_i18n
end

.setup_for_rails_2_1Object



46
47
48
# File 'lib/validates_timeliness.rb', line 46

def setup_for_rails_2_1
  load_error_messages_without_i18n
end

.setup_for_rails_2_2Object



50
51
52
# File 'lib/validates_timeliness.rb', line 50

def setup_for_rails_2_2
  load_error_messages_with_i18n
end