Module: ValidatesTimeliness

Defined in:
lib/validates_timeliness.rb,
lib/validates_timeliness/parser.rb,
lib/validates_timeliness/formats.rb,
lib/validates_timeliness/version.rb,
lib/validates_timeliness/validator.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, Parser, ValidationMethods Classes: Formats, Validator

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.enable_active_record_datetime_parser!Object



3
4
5
# File 'lib/validates_timeliness/active_record/attribute_methods.rb', line 3

def self.enable_active_record_datetime_parser!
  ::ActiveRecord::Base.send(:include, ValidatesTimeliness::ActiveRecord::AttributeMethods)
end

.enable_datetime_select_extension!Object



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

def enable_datetime_select_extension!
  enable_datetime_select_invalid_value_extension!
  enable_multiparameter_attributes_extension!
end

.enable_datetime_select_invalid_value_extension!Object



3
4
5
# File 'lib/validates_timeliness/action_view/instance_tag.rb', line 3

def self.enable_datetime_select_invalid_value_extension!
  ::ActionView::Helpers::InstanceTag.send(:include, ValidatesTimeliness::ActionView::InstanceTag)
end

.enable_multiparameter_attributes_extension!Object



3
4
5
# File 'lib/validates_timeliness/active_record/multiparameter_attributes.rb', line 3

def self.enable_multiparameter_attributes_extension!
  ::ActiveRecord::Base.send(:include, ValidatesTimeliness::ActiveRecord::MultiparameterAttributes)
end

.load_error_messagesObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/validates_timeliness.rb', line 27

def load_error_messages
  if defined?(I18n)
    I18n.load_path.unshift(LOCALE_PATH)
    I18n.reload!
  else
    defaults = YAML::load(IO.read(LOCALE_PATH))['en']
    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)

    ValidatesTimeliness::Validator.error_value_formats = defaults['validates_timeliness']['error_value_formats'].symbolize_keys
  end
end

.setup_for_railsObject



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

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