validation 0.0.3 → 0.0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ coverage.data
7
+ InstalledFiles
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # bundler
17
+ vendor/
18
+
19
+ # YARD artifacts
20
+ .yardoc
21
+ _yardoc
22
+ doc/
23
+
24
+ # tmp-old
25
+ .old
26
+
27
+ # editor
28
+ *~
29
+ .redcar
30
+
31
+ # other
32
+ *.lock
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - ruby-head
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - jruby-head
7
+ - jruby-19mode # JRuby in 1.9 mode
8
+ - rbx-19mode # Rubinius in 1.9 mode
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'rake'
7
+ gem 'yard', '>=0.8.2.1'
8
+ gem 'rdoc', '>=3.12'
9
+ end
10
+
11
+ group :test do
12
+ gem 'rake'
13
+ end
@@ -1,18 +1,26 @@
1
- === 0.0.3 2012-04-03
2
-
3
- * modify:
4
- * Support Module and Exceptions NameSpace
5
- * Conditions.#CATCH("also" .#RESCUE -> "and" .#RESCUE)
6
-
7
- === 0.0.2 2012-04-02
8
-
9
- * fix:
10
- * Adjustment.#WHEN
11
- * Exception namespace and dealing
12
- * Validatable behavior on ruby1.9.2
13
-
14
- === 0.0.1 2012-04-01
15
-
16
- * 1 major enhancement:
17
- * Initial release
18
-
1
+ === 0.0.3.1 2012-08-25
2
+
3
+ * modify:
4
+
5
+ * Adjust test-case for YAML in Ruby1.9.2
6
+ * Adjust test-case for JRuby bugs
7
+ * Name of Exceptions sequence changed
8
+
9
+ === 0.0.3 2012-04-03
10
+
11
+ * modify:
12
+ * Support Module and Exceptions NameSpace
13
+ * Conditions.#CATCH("also" .#RESCUE -> "and" .#RESCUE)
14
+
15
+ === 0.0.2 2012-04-02
16
+
17
+ * fix:
18
+ * Adjustment.#WHEN
19
+ * Exception namespace and dealing
20
+ * Validatable behavior on ruby1.9.2
21
+
22
+ === 0.0.1 2012-04-01
23
+
24
+ * 1 major enhancement:
25
+ * Initial release
26
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT X License)
2
+
3
+ Copyright (c) 2011-2012 Kenichi Kamiya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,13 +1,20 @@
1
1
  README.rdoc
2
+ LICENSE
2
3
  History.rdoc
3
4
  Manifest.txt
4
5
  Rakefile
6
+ Gemfile
7
+ validation.gemspec
5
8
  lib/validation.rb
6
- lib/validation/core.rb
9
+ lib/validation/requirements.rb
10
+ lib/validation/version.rb
11
+ lib/validation/errors.rb
7
12
  lib/validation/condition.rb
8
13
  lib/validation/adjustment.rb
9
14
  lib/validation/validatable.rb
10
- lib/validation/version.rb
15
+ lib/validation/validatable/classmethods.rb
16
+ lib/validation/singleton_class.rb
17
+ lib/validation/module_functions.rb
11
18
  test/test_helper.rb
12
19
  test/test_validation.rb
13
- example/example.rb
20
+ examples/example.rb
@@ -1,49 +1,63 @@
1
- = Validation
2
-
3
- * http://github.com/kachick/validation
4
- * http://rubygems.org/gems/validation
5
- * http://rubyforge.org/projects/validation
6
-
7
- == Description
8
-
9
- A way of defining validations anywhere.
10
-
11
- == Features
12
-
13
- * Easy and Flexible Validations
14
- * Hook just before running setters
15
- * Pure Ruby :)
16
-
17
- == Usage
18
-
19
- * setup
20
- require 'validation'
21
-
22
- * a case
23
- class Person
24
- include Validation
25
-
26
- attr_validator :name, String
27
- attr_validator :id, OR(nil, AND(Integer, 1..100))
28
- end
29
-
30
- * (writing...) # see Striuct
31
-
32
- == Requirements
33
-
34
- * Ruby 1.9.2 or later
35
-
36
- target release versions
37
-
38
- * 1.9.3-p125
39
- * 1.9.2-p290
40
-
41
- == Installation
42
-
43
- * gem install validation
44
-
45
- == License
46
-
47
- Copyright (C) 2011-2012 Kenichi Kamiya
48
-
49
- The MIT License (See the file LICENSE)
1
+ = validation
2
+
3
+ {<img src="https://secure.travis-ci.org/kachick/validation.png" />}[http://travis-ci.org/kachick/validation]
4
+
5
+ == Description
6
+
7
+ Support validations
8
+
9
+ == Features
10
+
11
+ * Provide a way of defining validations anywhere.
12
+ * Easy and Flexible validation combinators.
13
+ * And adjusters.
14
+ * Pure Ruby :)
15
+
16
+ == Usage
17
+
18
+ === Setup
19
+
20
+ require 'validation'
21
+
22
+ === Validatable
23
+
24
+ class Person
25
+
26
+ include Validation
27
+
28
+ attr_validator :name, String
29
+ attr_validator :id, OR(nil, AND(Integer, 1..100))
30
+
31
+ end
32
+
33
+ === More Examples
34
+
35
+ See below libraries
36
+
37
+ * {striuct}[https://github.com/kachick/striuct]
38
+ * {io-nosey}[https://github.com/kachick/io-nosey]
39
+ * {family}[https://github.com/kachick/family]
40
+
41
+ == Requirements
42
+
43
+ * Ruby 1.9.2 or later ({MRI/YARV, Rubinius, JRuby}[http://travis-ci.org/#!/kachick/validation])
44
+
45
+ == Installation
46
+
47
+ $ gem install validation
48
+
49
+ == Links
50
+
51
+ code :: https://github.com/kachick/validation
52
+ issues :: https://github.com/kachick/validation/issues
53
+ CI :: http://travis-ci.org/#!/kachick/validation
54
+ gem :: https://rubygems.org/gems/validation
55
+ gem+ :: http://metagem.info/gems/validation
56
+
57
+ == License
58
+
59
+ The MIT X License
60
+
61
+ Copyright (C) 2011-2012 Kenichi Kamiya
62
+
63
+ See the file LICENSE for further details.
data/Rakefile CHANGED
@@ -1,24 +1,11 @@
1
- require 'rubygems'
2
- gem 'hoe', '~> 3.0.1'
3
- require 'hoe'
4
- require 'fileutils'
5
-
6
- Hoe.plugin :newgem
7
- # Hoe.plugin :website
8
- # Hoe.plugin :cucumberfeatures
9
-
10
- # Generate all the Rake tasks
11
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
12
- $hoe = Hoe.spec 'validation' do
13
- developer 'Kenichi Kamiya', 'kachick1+ruby@gmail.com'
14
- self.rubyforge_name = self.name
15
- require_ruby_version '>= 1.9.2'
16
- dependency 'yard', '~> 0.7.5', :development
17
- end
18
-
19
- require 'newgem/tasks'
20
- Dir['tasks/**/*.rake'].each { |t| load t }
21
-
22
- # TODO - want other tests/tasks run by default? Add them to the list
23
- # remove_task :default
24
- # task :default => [:spec, :features]
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+
4
+ require 'rake/testtask'
5
+
6
+ task default: [:test]
7
+
8
+ Rake::TestTask.new do |tt|
9
+ tt.verbose = true
10
+ end
11
+
@@ -1,27 +1,27 @@
1
- $VERBOSE = true
2
-
3
- require_relative '../lib/validation'
4
-
5
- class MyClass
6
- include Validation
7
-
8
- p ancestors
9
- p respond_to?(:attr_validator, false)
10
- p respond_to?(:attr_validator, true)
11
-
12
- attr_validator :name, String
13
- attr_validator :id, OR(nil, AND(Integer, 1..100))
14
- end
15
-
16
- my = MyClass.new
17
- #~ my.name = 8 #=> error
18
- my.name = 'Ken'
19
- #~ my.name = nil #=> error
20
- p my
21
-
22
- my.id = nil
23
- #~ my.id = 'fail' #=> error
24
- #~ my.id = 101 #=> error
25
- #~ my.id = 99.9 #=> error
26
- my.id = 100
27
- p my
1
+ $VERBOSE = true
2
+
3
+ require_relative '../lib/validation'
4
+
5
+ class MyClass
6
+ include Validation
7
+
8
+ p ancestors
9
+ p respond_to?(:attr_validator, false)
10
+ p respond_to?(:attr_validator, true)
11
+
12
+ attr_validator :name, String
13
+ attr_validator :id, OR(nil, AND(Integer, 1..100))
14
+ end
15
+
16
+ my = MyClass.new
17
+ #~ my.name = 8 #=> error
18
+ my.name = 'Ken'
19
+ #~ my.name = nil #=> error
20
+ p my
21
+
22
+ my.id = nil
23
+ #~ my.id = 'fail' #=> error
24
+ #~ my.id = 101 #=> error
25
+ #~ my.id = 99.9 #=> error
26
+ my.id = 100
27
+ p my
@@ -1,11 +1,7 @@
1
- # Copyright (C) 2011-2012 Kenichi Kamiya
1
+ # Copyright (c) 2011-2012 Kenichi Kamiya
2
2
 
3
- # Code base from Striuct
4
- # http://github.com/kachick/striuct
5
- # http://rubygems.org/gems/striuct
3
+ module Validation
4
+ end
5
+
6
+ require_relative 'validation/requirements'
6
7
 
7
- require_relative 'validation/core'
8
- require_relative 'validation/condition'
9
- require_relative 'validation/adjustment'
10
- require_relative 'validation/validatable'
11
- require_relative 'validation/version'
@@ -1,80 +1,85 @@
1
- # Copyright (C) 2011-2012 Kenichi Kamiya
2
-
3
- module Validation
4
-
5
- module Adjustment
6
- module_function
7
-
8
- # @group Support Building Adjusters
9
-
10
- # true if argument is sufficient for adjuster.
11
- # A adjuster have to be arity equal 1.
12
- # @param [Object] object
13
- def adjustable?(object)
14
- case object
15
- when Proc
16
- object.arity == 1
17
- else
18
- if object.respond_to?(:to_proc)
19
- object.to_proc.arity == 1
20
- else
21
- false
22
- end
23
- end
24
- end
25
-
26
- # Adjuster Builders
27
- # Apply adjuster when passed condition.
28
- # @return [lambda]
29
- def WHEN(condition, adjuster)
30
- raise TypeError, 'wrong object for condition' unless Validation.conditionable? condition
31
- raise TypeError, 'wrong object for adjuster' unless Validation.adjustable? adjuster
32
-
33
- ->v{_valid?(condition, v) ? adjuster.call(v) : v}
34
- end
35
-
36
- # Sequencial apply all adjusters.
37
- # @return [lambda]
38
- def INJECT(adjuster1, adjuster2, *adjusters)
39
- adjusters = [adjuster1, adjuster2, *adjusters]
40
-
41
- unless adjusters.all?{|f|adjustable? f}
42
- raise TypeError, 'wrong object for adjuster'
43
- end
44
-
45
- ->v{
46
- adjusters.reduce(v){|ret, adjuster|adjuster.call ret}
47
- }
48
- end
49
-
50
- # Accept any parser when that resopond to parse method.
51
- # @return [lambda]
52
- def PARSE(parser)
53
- if !::Integer.equal?(parser) and !parser.respond_to?(:parse)
54
- raise TypeError, 'wrong object for parser'
55
- end
56
-
57
- ->v{
58
- if ::Integer.equal? parser
59
- ::Kernel.Integer v
60
- else
61
- parser.parse(
62
- case v
63
- when String
64
- v
65
- when ->_{v.respond_to? :to_str}
66
- v.to_str
67
- when ->_{v.respond_to? :read}
68
- v.read
69
- else
70
- raise TypeError, 'wrong object for parsing source'
71
- end
72
- )
73
- end
74
- }
75
- end
76
-
77
- # @endgroup
78
- end
79
-
80
- end
1
+ module Validation
2
+
3
+ module Adjustment
4
+
5
+ module_function
6
+
7
+ # @group Support Building Adjusters
8
+
9
+ # true if argument is sufficient for adjuster.
10
+ # A adjuster have to be arity equal 1.
11
+ # @param [Object] object
12
+ def adjustable?(object)
13
+ case object
14
+ when Proc
15
+ object.arity == 1
16
+ else
17
+ if object.respond_to?(:to_proc)
18
+ object.to_proc.arity == 1
19
+ else
20
+ false
21
+ end
22
+ end
23
+ end
24
+
25
+ # Adjuster Builders
26
+ # Apply adjuster when passed condition.
27
+ # @return [lambda]
28
+ def WHEN(condition, adjuster)
29
+ unless Validation.conditionable? condition
30
+ raise TypeError, 'wrong object for condition'
31
+ end
32
+
33
+ unless Validation.adjustable? adjuster
34
+ raise TypeError, 'wrong object for adjuster'
35
+ end
36
+
37
+ ->v{_valid?(condition, v) ? adjuster.call(v) : v}
38
+ end
39
+
40
+ # Sequencial apply all adjusters.
41
+ # @return [lambda]
42
+ def INJECT(adjuster1, adjuster2, *adjusters)
43
+ adjusters = [adjuster1, adjuster2, *adjusters]
44
+
45
+ unless adjusters.all?{|f|adjustable? f}
46
+ raise TypeError, 'wrong object for adjuster'
47
+ end
48
+
49
+ ->v{
50
+ adjusters.reduce(v){|ret, adjuster|adjuster.call ret}
51
+ }
52
+ end
53
+
54
+ # Accept any parser when that resopond to parse method.
55
+ # @return [lambda]
56
+ def PARSE(parser)
57
+ if !::Integer.equal?(parser) and !parser.respond_to?(:parse)
58
+ raise TypeError, 'wrong object for parser'
59
+ end
60
+
61
+ ->v{
62
+ if ::Integer.equal? parser
63
+ ::Kernel.Integer v
64
+ else
65
+ parser.parse(
66
+ case v
67
+ when String
68
+ v
69
+ when ->_{v.respond_to? :to_str}
70
+ v.to_str
71
+ when ->_{v.respond_to? :read}
72
+ v.read
73
+ else
74
+ raise TypeError, 'wrong object for parsing source'
75
+ end
76
+ )
77
+ end
78
+ }
79
+ end
80
+
81
+ # @endgroup
82
+
83
+ end
84
+
85
+ end