validation_hints 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
# == Active Model Hints
|
3
|
+
#
|
4
|
+
# more documentation needed
|
5
|
+
|
6
|
+
class Errors
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
def has_validations_for?(attribute)
|
10
|
+
! self.class.validators_on(attribute).empty?
|
11
|
+
end
|
12
|
+
|
13
|
+
def has_validations?(object, attribute)
|
14
|
+
object.class.validators_on(attribute).empty? ? "" : 'has_validations '
|
15
|
+
end
|
16
|
+
|
17
|
+
def validation_help_as_list_for(object, attribute)
|
18
|
+
has_validations?(object, attribute) ? content_tag(:ul, validation_help_for(object, attribute).map { |m| content_tag(:li, m ) }.join.html_safe ) : ""
|
19
|
+
end
|
20
|
+
|
21
|
+
# validation_help_for(object, attribute) extracts the help messages for
|
22
|
+
# attribute of object.class (in an Array)
|
23
|
+
def validation_help_for(object, attribute)
|
24
|
+
object.class.validators_on(attribute).map do |v|
|
25
|
+
key = v.class.to_s.underscore
|
26
|
+
regex = /\//
|
27
|
+
main_key = key.match(regex) ? key.gsub('/','.') : "inline_forms.validations." + key
|
28
|
+
[ t(main_key), v.options.keys.map do |o|
|
29
|
+
t(main_key + "." + o.to_s)
|
30
|
+
end ].flatten
|
31
|
+
end.flatten.compact
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validation_hints
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -136,9 +136,10 @@ files:
|
|
136
136
|
- LICENSE.txt
|
137
137
|
- README.md
|
138
138
|
- Rakefile
|
139
|
-
-
|
139
|
+
- lib/active_model/hints.rb
|
140
140
|
- lib/validation_hints.rb
|
141
141
|
- lib/validation_hints/version.rb
|
142
|
+
- validation_hints.gemspec
|
142
143
|
homepage: http://github.com/acesuares/validation_hints
|
143
144
|
licenses:
|
144
145
|
- MIT
|