validatable2 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,10 +3,7 @@ module Validatable
3
3
  #
4
4
  # Returns true if no errors were added otherwise false. Only executes validations that have no :groups option specified
5
5
  def valid?
6
- errors.clear
7
- self.class.all_validations.each do |validation|
8
- validation.validate self
9
- end
6
+ validate
10
7
  errors.empty?
11
8
  end
12
9
 
@@ -17,6 +14,15 @@ module Validatable
17
14
  @_errors ||= Validatable::Errors.new
18
15
  end
19
16
 
17
+ def validate
18
+ return true unless errors.empty?
19
+
20
+ self.class.all_validations.each do |validation|
21
+ validation.validate self
22
+ end
23
+ errors.empty?
24
+ end
25
+
20
26
  module ClassMethods #:nodoc:
21
27
  include ::Validatable::Macros
22
28
 
@@ -1,9 +1,10 @@
1
1
  module Validatable
2
2
  class ValidationBase #:nodoc:
3
3
  attr_accessor :message, :if, :after_validate, :allow_nil, :allow_blank
4
- attr_accessor :attribute
4
+ attr_accessor :attribute, :klass
5
5
 
6
6
  def initialize(klass, attribute, options={})
7
+ self.klass = klass
7
8
  options.each{|k, v| self.send :"#{k}=", v}
8
9
  self.attribute = attribute
9
10
  end
data/readme.md CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
  Validatable is a library for adding validations.
4
4
 
5
- In version 2 I removed all dependencies and extra stuff and left only pure validation logic.
5
+ In version 2 I removed all dependencies and extra stuff and left only pure validation logic.
6
6
  You can use these validations with any plain Ruby object, and not only wit ActiveRecord-compatible models.
7
7
 
8
+ Here's the code stats - before and after [![code_stats_thumb]][code_stats] (made by [CodeStats][code_stats_tool]).
9
+
8
10
  Also, I removed the "self.included ..." hook (because it caused problems with some libraries), if You need it (and You probably do) add this line after requiring 'validatable':
9
11
 
10
12
  ``` ruby
@@ -132,4 +134,8 @@ In the above example the attribute "name" is appended to the message.
132
134
  See the tests for more examples
133
135
 
134
136
  == Contributors
135
- Rick Bradley, Anonymous Z, Jason Miller, Ali Aghareza, Xavier Shay, Dan Manges, Karthik Krishnan and Venkat, Clint Bishop, Chris Didyk, Yi Wen
137
+ Rick Bradley, Anonymous Z, Jason Miller, Ali Aghareza, Xavier Shay, Dan Manges, Karthik Krishnan and Venkat, Clint Bishop, Chris Didyk, Yi Wen
138
+
139
+ [code_stats]: https://github.com/alexeypetrushin/validatable2/raw/master/doc/code_stats.png
140
+ [code_stats_thumb]: https://github.com/alexeypetrushin/validatable2/raw/master/doc/code_stats.thumb.png
141
+ [code_stats_tool]: https://github.com/alexeypetrushin/code_stats
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validatable2
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: