validation_hints 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/active_model/hints.rb +37 -11
- data/lib/validation_hints/version.rb +1 -1
- data/lib/validation_hints.rb +6 -5
- metadata +1 -1
data/lib/active_model/hints.rb
CHANGED
@@ -3,25 +3,51 @@ module ActiveModel
|
|
3
3
|
#
|
4
4
|
# more documentation needed
|
5
5
|
|
6
|
-
class
|
6
|
+
class Hints
|
7
7
|
include Enumerable
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
attr_reader :messages
|
10
|
+
|
11
|
+
# Pass in the instance of the object that is using the errors object.
|
12
|
+
#
|
13
|
+
# class Person
|
14
|
+
# def initialize
|
15
|
+
# @errors = ActiveModel::Errors.new(self)
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
def initialize(base)
|
19
|
+
@base = base
|
20
|
+
@messages = ActiveSupport::OrderedHash.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize_dup(other)
|
24
|
+
@messages = other.messages.dup
|
11
25
|
end
|
12
26
|
|
13
|
-
|
14
|
-
|
27
|
+
# Backport dup from 1.9 so that #initialize_dup gets called
|
28
|
+
unless Object.respond_to?(:initialize_dup)
|
29
|
+
def dup # :nodoc:
|
30
|
+
copy = super
|
31
|
+
copy.initialize_dup(self)
|
32
|
+
copy
|
33
|
+
end
|
15
34
|
end
|
16
35
|
|
17
|
-
|
18
|
-
|
36
|
+
# Clear the messages
|
37
|
+
def clear
|
38
|
+
messages.clear
|
19
39
|
end
|
20
40
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
41
|
+
def show
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
def t(a)
|
46
|
+
a
|
47
|
+
end
|
48
|
+
|
49
|
+
def validation_help_for(attribute)
|
50
|
+
@base.class.validators_on(attribute).map do |v|
|
25
51
|
key = v.class.to_s.underscore
|
26
52
|
regex = /\//
|
27
53
|
main_key = key.match(regex) ? key.gsub('/','.') : "inline_forms.validations." + key
|
data/lib/validation_hints.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
|
-
require 'active_support'
|
4
3
|
require 'validation_hints/version'
|
4
|
+
require 'active_model/hints'
|
5
5
|
|
6
6
|
module ActiveModel
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
module Validations
|
8
|
+
def hints
|
9
|
+
@hints ||= Hints.new(self)
|
10
|
+
end
|
11
|
+
end
|
11
12
|
end
|
12
13
|
|
13
14
|
require 'active_support/i18n'
|