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
@@ -13,4 +13,6 @@ capybara-*.html
13
13
  /spec/tmp/*
14
14
  **.orig
15
15
  rerun.txt
16
- pickle-email-*.html
16
+ pickle-email-*.html
17
+ /pkg
18
+ .rvmrc
@@ -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
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module ValidationHints
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  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.1
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
- - inline_forms.gemspec
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