not_naughty 0.3.1 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.4 (2008-02-18)
2
+ * completed documentation
3
+ * added spec for :each in Builder::ValidationDelegator
4
+
1
5
  === 0.3.1 (2008-02-14)
2
6
  * fixed missing require
3
7
 
data/README CHANGED
@@ -1,36 +1,11 @@
1
1
  = NotNaughty - The Validation Framework
2
2
 
3
- <b>Features:</b>
4
- * API compatible to Sequel as plugin (see Sequel::Plugins::NotNaughty for
5
- details):
3
+ NotNaughty extends your ruby Project with a highly custumizable validation API.
6
4
 
7
- class User < Sequel::Model
8
- is :not_naughty
9
- validates { presence_of :username and length_of :username, :within => 4..16 }
10
- has_validations? # => true
11
-
12
- # ...
13
- end
14
-
15
- * Syntactical Sugar with Builder methods:
16
-
17
- validates(:username, :password) {length :minimum => 6}
18
- validates(:password) {confirmed and complexity :level => :high}
19
- validates(:if => :necessary?) {bunchyness_of :crap}
5
+ == Features
20
6
 
21
- * Beautiful error messages:
7
+ <b>Easy to adapt:</b>
22
8
 
23
- validates_presence_of :person,
24
- :message => '#{"%s".humanize} is gone missing.'
25
-
26
- * Conditional Validations:
27
-
28
- validates(:if => :necessary?) {...}
29
- validates(:unless => proc {|obj| obj.vip?}) {...}
30
-
31
- * Easy to adapt and to extent:
32
-
33
- _adapt_
34
9
  require 'rubygems'
35
10
  require 'not_naughty'
36
11
  Person = Struct.new(:name) do
@@ -44,7 +19,8 @@
44
19
  Person.new('Foo').clone # goes *boom* with NotNaughty::ValidationException
45
20
  Person.new('Foo').dup # => false
46
21
 
47
- _extend_
22
+ <b>Easy to extent:</b>
23
+
48
24
  class BunchynessValidation < NotNaughty::Validation
49
25
  def initialize(opts, attributes)
50
26
  __message = opts[:message] || '#{"%s".humanize} is not bunchy.'
@@ -59,4 +35,34 @@
59
35
  validates_bunchyness_of :bunchy_item
60
36
  end
61
37
 
38
+ <b>Syntactical Sugar with Builder methods:</b>
39
+
40
+ validates(:username, :password) {length :minimum => 6}
41
+ validates(:password) {confirmed and complexity :level => :high}
42
+ validates(:if => :necessary?) {bunchyness_of :crap}
43
+
44
+ <b>Beautiful error messages:</b>
45
+
46
+ validates_presence_of :person,
47
+ :message => '#{"%s".humanize} is gone missing.'
48
+
49
+ <b>Conditional Validations:</b>
50
+
51
+ validates(:if => :necessary?) {...}
52
+ validates(:unless => proc {|obj| obj.vip?}) {...}
53
+
54
+ <b>API compatible to Ruby-Sequel[http://code.google.com/p/ruby-sequel/] as plugin:</b>
55
+
56
+ class User < Sequel::Model
57
+ is :not_naughty
58
+ validates { presence_of :username and length_of :username, :within => 4..16 }
59
+ has_validations? # => true
60
+
61
+ # ...
62
+ end
63
+
64
+ See Sequel::Plugins::NotNaughty for details...
65
+
66
+ == Copying
67
+
62
68
  :include: COPYING
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ include FileUtils
9
9
  # Configuration
10
10
  ##############################################################################
11
11
  NAME = "not_naughty"
12
- VERS = "0.3.1"
12
+ VERS = "0.4"
13
13
  CLEAN.include ["**/.*.sw?", "pkg/*", ".config", "doc/*", "coverage/*"]
14
14
  RDOC_OPTS = [
15
15
  "--quiet",
@@ -1,21 +1,28 @@
1
1
  module NotNaughty
2
2
 
3
- # == Validates acceptance of obj's attribute against a fixed value.
3
+ # == Validates acceptance of obj's attribute against a fixed value via <tt>:eql?</tt> call.
4
4
  #
5
5
  # Unless the validation succeeds an error hash (:attribute => :message)
6
6
  # is added to the obj's instance of Errors.
7
7
  #
8
8
  # <b>Options:</b>
9
- # <tt>:accept</tt>:: object that that'll check via a <tt>:match</tt> call
9
+ # <tt>:accept</tt>:: object to check against (via :eql?)
10
10
  # <tt>:message</tt>:: see NotNaughty::Errors for details
11
11
  # <tt>:if</tt>:: see NotNaughty::Validation::Condition for details
12
12
  # <tt>:unless</tt>:: see NotNaughty::Validation::Condition for details
13
13
  #
14
14
  # <b>Example:</b>
15
15
  #
16
- # obj = 'abc'
17
- # def obj.errors() @errors ||= NotNauthy::Errors.new end
16
+ # invalid = 'abc'
17
+ # valid = '1'
18
+ # def invalid.errors() @errors ||= NotNauthy::Errors.new end
19
+ # def valid.errors() @errors ||= NotNauthy::Errors.new end
18
20
  #
21
+ # AcceptanceValidation.new({}, :to_s).call invalid, :to_s, 'abc'
22
+ # invalid.errors.on(:to_s).any? # => true
23
+ #
24
+ # AcceptanceValidation.new({}, :to_s).call valid, :to_s, '1'
25
+ # valid.errors.on(:to_s).any? # => false
19
26
  class AcceptanceValidation < Validation
20
27
 
21
28
  def initialize(opts, attributes)
@@ -1,6 +1,6 @@
1
1
  module NotNaughty
2
2
 
3
- # == Validates confirmaton of obj's attribute via <tt>:eql?</tt> method against the _appropiate_ confirmation attribute.
3
+ # == Validates confirmaton of obj's attribute via <tt>:eql?</tt> call against the _appropiate_ confirmation attribute.
4
4
  #
5
5
  # Unless the validation succeeds an error hash (:attribute => :message)
6
6
  # is added to the obj's instance of Errors.
@@ -22,7 +22,7 @@ module NotNaughty
22
22
 
23
23
  def initialize(opts, attributes) #:nodoc:
24
24
  __message = opts[:message] || '#{"%s".humanize} could not be confirmed.'
25
-
25
+
26
26
  if opts[:allow_blank] or opts[:allow_nil]
27
27
  __allow = if opts[:allow_blank] then :blank? else :nil? end
28
28
  super opts, attributes do |o, a, v|
@@ -15,25 +15,41 @@ module Sequel #:nodoc:
15
15
  # is :not_naughty
16
16
  # end
17
17
  #
18
- # <b>To turn off before_validate and after_validate hooks:</b>
18
+ # ---
19
+ #
20
+ # <b>Options:</b>
21
+ #
22
+ # <i>To turn off before_validate and after_validate hooks:</i>
19
23
  #
20
24
  # class User < Sequel::Model
21
25
  # is :not_naughty, :without => :hooks
22
26
  # end
23
27
  #
24
- # <b>To turn off raised Exceptions if validation before save fails:</b>
28
+ # <i>To turn off raised Exceptions if validation before save fails:</i>
25
29
  #
26
30
  # class User < Sequel::Model
27
31
  # # save on invalid users will return false
28
32
  # is :not_naughty, :without => :exceptions
29
33
  # end
30
34
  #
31
- # <b>To combine those:</b>
35
+ # <i>To combine those:</i>
32
36
  #
33
37
  # class User < Sequel::Model
34
38
  # is :not_naughty, :without => [:exceptions, :hooks]
35
39
  # end
36
40
  #
41
+ # ---
42
+ #
43
+ # <b>API compatibility:</b>
44
+ #
45
+ # The validates_length_of method does only one check per attribute.
46
+ # If you want to check minimum and maximum length with different error
47
+ # messages you need to write 2 validations:
48
+ #
49
+ # validates_length_of :name, :minimum => 4
50
+ # validates_length_of :name, :maximum => 12
51
+ #
52
+ # Except the example above the Plugin should be 100% API compatible.
37
53
  class NotNaughty < NotNaughty::Validator
38
54
 
39
55
  # Applies plugin to a Sequel::Model.
data/spec/builder_spec.rb CHANGED
@@ -61,6 +61,17 @@ describe subject::Builder do
61
61
 
62
62
  pending 'expect a block'
63
63
  end
64
+ it "should support :each in validates block" do
65
+ @validatable.validator = mock 'Validator'
66
+ @validatable.validator.
67
+ should_receive(:add_validation).
68
+ with(:a, :b, {})
69
+ @validatable.validates do
70
+ each(:a, :b) {|o, a, v|}
71
+ end
72
+
73
+ pending 'expect a block'
74
+ end
64
75
  it "should raise a NoMethodError is builder method does not exist" do
65
76
  lambda { @validatable.validates() { bunch_of :holy_crap } }.
66
77
  should raise_error(NoMethodError)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: not_naughty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: "0.4"
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Florian A\xC3\x9Fmann"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-02-14 00:00:00 +01:00
12
+ date: 2008-02-18 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15