validation_hints 0.0.3 → 0.0.4

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.
@@ -3,25 +3,51 @@ module ActiveModel
3
3
  #
4
4
  # more documentation needed
5
5
 
6
- class Errors
6
+ class Hints
7
7
  include Enumerable
8
8
 
9
- def has_validations_for?(attribute)
10
- ! self.class.validators_on(attribute).empty?
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
- def has_validations?(object, attribute)
14
- object.class.validators_on(attribute).empty? ? "" : 'has_validations '
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
- 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 ) : ""
36
+ # Clear the messages
37
+ def clear
38
+ messages.clear
19
39
  end
20
40
 
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|
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
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module ValidationHints
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
@@ -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
- extend ActiveSupport::Autoload
8
-
9
- autoload :Hints
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'
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.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: