knight 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/Gemfile +7 -0
- data/Gemfile.dev +16 -0
- data/README.md +3 -1
- data/Rakefile +6 -1
- data/knight.gemspec +4 -1
- data/lib/knight.rb +18 -2
- data/lib/knight/error.rb +60 -0
- data/lib/knight/instance_methods.rb +69 -0
- data/lib/knight/result.rb +86 -0
- data/lib/knight/rule.rb +74 -0
- data/lib/knight/rule/exact_length.rb +63 -0
- data/lib/knight/rule/format.rb +62 -0
- data/lib/knight/rule/inclusion.rb +62 -0
- data/lib/knight/rule/maximum_length.rb +63 -0
- data/lib/knight/rule/minimum_length.rb +63 -0
- data/lib/knight/rule/presence.rb +37 -0
- data/lib/knight/rule/range_length.rb +64 -0
- data/lib/knight/validator.rb +91 -0
- data/lib/knight/version.rb +3 -1
- data/metrics/flog.yml +2 -0
- data/metrics/rubocop.yml +17 -0
- data/spec/integration/contextual_validator_spec.rb +41 -0
- data/spec/integration/knight_spec.rb +30 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/unit/knight/error/class_methods/new_spec.rb +15 -0
- data/spec/unit/knight/error/message_spec.rb +26 -0
- data/spec/unit/knight/instance_methods/class_methods/included_spec.rb +24 -0
- data/spec/unit/knight/instance_methods/class_methods/new_spec.rb +12 -0
- data/spec/unit/knight/instance_methods/class_methods/validator_spec.rb +13 -0
- data/spec/unit/knight/instance_methods/run_spec.rb +29 -0
- data/spec/unit/knight/result/class_methods/new_spec.rb +13 -0
- data/spec/unit/knight/result/errors_spec.rb +71 -0
- data/spec/unit/knight/result/valid_predicate_spec.rb +28 -0
- data/spec/unit/knight/rule/class_methods/new_spec.rb +38 -0
- data/spec/unit/knight/rule/error_spec.rb +29 -0
- data/spec/unit/knight/rule/exact_length/class_methods/new_spec.rb +27 -0
- data/spec/unit/knight/rule/exact_length/matches_predicate_spec.rb +19 -0
- data/spec/unit/knight/rule/exact_length/to_hash_spec.rb +12 -0
- data/spec/unit/knight/rule/format/class_methods/new_spec.rb +26 -0
- data/spec/unit/knight/rule/format/matches_predicate_spec.rb +31 -0
- data/spec/unit/knight/rule/format/to_hash_spec.rb +12 -0
- data/spec/unit/knight/rule/inclusion/class_methods/new_spec.rb +28 -0
- data/spec/unit/knight/rule/inclusion/matches_predicate_spec.rb +48 -0
- data/spec/unit/knight/rule/inclusion/to_hash_spec.rb +12 -0
- data/spec/unit/knight/rule/maximum_length/class_methods/new_spec.rb +27 -0
- data/spec/unit/knight/rule/maximum_length/matches_predicate_spec.rb +21 -0
- data/spec/unit/knight/rule/maximum_length/to_hash_spec.rb +12 -0
- data/spec/unit/knight/rule/minimum_length/class_methods/new_spec.rb +27 -0
- data/spec/unit/knight/rule/minimum_length/matches_predicate_spec.rb +21 -0
- data/spec/unit/knight/rule/minimum_length/to_hash_spec.rb +12 -0
- data/spec/unit/knight/rule/presence/matches_predicate_spec.rb +27 -0
- data/spec/unit/knight/rule/range_length/class_methods/new_spec.rb +27 -0
- data/spec/unit/knight/rule/range_length/matches_predicate_spec.rb +19 -0
- data/spec/unit/knight/rule/range_length/to_hash_spec.rb +12 -0
- data/spec/unit/knight/rule/to_hash_spec.rb +13 -0
- data/spec/unit/knight/validator/add_spec.rb +29 -0
- data/spec/unit/knight/validator/class_methods/new_spec.rb +18 -0
- data/spec/unit/knight/validator/context_spec.rb +13 -0
- data/spec/unit/knight/validator/rules_spec.rb +29 -0
- data/spec/unit/knight/validator/run_spec.rb +26 -0
- metadata +138 -6
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Validator, '.new' do
|
6
|
+
subject { described_class.new(*rules) }
|
7
|
+
|
8
|
+
let(:rules) do
|
9
|
+
[
|
10
|
+
Rule::Presence.new(:title),
|
11
|
+
Rule::Presence.new(:title),
|
12
|
+
Rule::Presence.new(:age),
|
13
|
+
Rule::ExactLength.new(:title, 20),
|
14
|
+
]
|
15
|
+
end
|
16
|
+
it { should be_instance_of(described_class) }
|
17
|
+
specify { expect(subject.rules.size).to eql(3) }
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe Validator, '#context' do
|
4
|
+
|
5
|
+
before do
|
6
|
+
validator.context :registration do |context|
|
7
|
+
context << Rule::Presence.new(:username)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:validator) { described_class.new }
|
12
|
+
specify { expect(validator.rules(:registration).size).to eql(1) }
|
13
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Validator, '#rules' do
|
6
|
+
|
7
|
+
let(:validator) { described_class.new(Rule::Presence.new(:username)) }
|
8
|
+
let(:resource) { double('resource') }
|
9
|
+
|
10
|
+
before do
|
11
|
+
validator.add(Rule::Presence.new(:title), :register)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'default context' do
|
15
|
+
subject { validator.rules }
|
16
|
+
specify { expect(subject.size).to eql(1) }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'register context' do
|
20
|
+
subject { validator.rules(:register) }
|
21
|
+
specify { expect(subject.size).to eql(1) }
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'not defined context' do
|
25
|
+
subject { validator.rules(:else) }
|
26
|
+
it { should be_instance_of(Set) }
|
27
|
+
specify { expect(subject.size).to eql(0) }
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Validator, '#run' do
|
6
|
+
|
7
|
+
let(:validator) { described_class.new(Rule::Presence.new(:username)) }
|
8
|
+
let(:resource) { double('resource') }
|
9
|
+
|
10
|
+
before do
|
11
|
+
validator.add(Rule::Presence.new(:title), :register)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'default context' do
|
15
|
+
subject { validator.run(resource) }
|
16
|
+
it { should be_instance_of(Result) }
|
17
|
+
its(:resource) { should eql(resource) }
|
18
|
+
specify { expect(subject.rules).to eql(validator.rules) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'register context' do
|
22
|
+
subject { validator.run(resource, :register) }
|
23
|
+
it { should be_instance_of(Result) }
|
24
|
+
specify { expect(subject.rules).to eql(validator.rules(:register)) }
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -2,30 +2,118 @@
|
|
2
2
|
name: knight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Handi Wiguna
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07
|
13
|
-
dependencies:
|
12
|
+
date: 2013-08-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
prerelease: false
|
16
|
+
name: equalizer
|
17
|
+
type: :runtime
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.0.5
|
23
|
+
none: false
|
24
|
+
requirement: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: 0.0.5
|
29
|
+
none: false
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
prerelease: false
|
32
|
+
name: abstract_type
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 0.0.5
|
39
|
+
none: false
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 0.0.5
|
45
|
+
none: false
|
14
46
|
description: ''
|
15
47
|
email:
|
16
|
-
-
|
48
|
+
- handi_wiguna@yahoo.com
|
17
49
|
executables: []
|
18
50
|
extensions: []
|
19
51
|
extra_rdoc_files: []
|
20
52
|
files:
|
21
53
|
- .gitignore
|
54
|
+
- .rspec
|
55
|
+
- .travis.yml
|
22
56
|
- Gemfile
|
57
|
+
- Gemfile.dev
|
23
58
|
- LICENSE.txt
|
24
59
|
- README.md
|
25
60
|
- Rakefile
|
26
61
|
- knight.gemspec
|
27
62
|
- lib/knight.rb
|
63
|
+
- lib/knight/error.rb
|
64
|
+
- lib/knight/instance_methods.rb
|
65
|
+
- lib/knight/result.rb
|
66
|
+
- lib/knight/rule.rb
|
67
|
+
- lib/knight/rule/exact_length.rb
|
68
|
+
- lib/knight/rule/format.rb
|
69
|
+
- lib/knight/rule/inclusion.rb
|
70
|
+
- lib/knight/rule/maximum_length.rb
|
71
|
+
- lib/knight/rule/minimum_length.rb
|
72
|
+
- lib/knight/rule/presence.rb
|
73
|
+
- lib/knight/rule/range_length.rb
|
74
|
+
- lib/knight/validator.rb
|
28
75
|
- lib/knight/version.rb
|
76
|
+
- metrics/flog.yml
|
77
|
+
- metrics/rubocop.yml
|
78
|
+
- spec/integration/contextual_validator_spec.rb
|
79
|
+
- spec/integration/knight_spec.rb
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
- spec/unit/knight/error/class_methods/new_spec.rb
|
82
|
+
- spec/unit/knight/error/message_spec.rb
|
83
|
+
- spec/unit/knight/instance_methods/class_methods/included_spec.rb
|
84
|
+
- spec/unit/knight/instance_methods/class_methods/new_spec.rb
|
85
|
+
- spec/unit/knight/instance_methods/class_methods/validator_spec.rb
|
86
|
+
- spec/unit/knight/instance_methods/run_spec.rb
|
87
|
+
- spec/unit/knight/result/class_methods/new_spec.rb
|
88
|
+
- spec/unit/knight/result/errors_spec.rb
|
89
|
+
- spec/unit/knight/result/valid_predicate_spec.rb
|
90
|
+
- spec/unit/knight/rule/class_methods/new_spec.rb
|
91
|
+
- spec/unit/knight/rule/error_spec.rb
|
92
|
+
- spec/unit/knight/rule/exact_length/class_methods/new_spec.rb
|
93
|
+
- spec/unit/knight/rule/exact_length/matches_predicate_spec.rb
|
94
|
+
- spec/unit/knight/rule/exact_length/to_hash_spec.rb
|
95
|
+
- spec/unit/knight/rule/format/class_methods/new_spec.rb
|
96
|
+
- spec/unit/knight/rule/format/matches_predicate_spec.rb
|
97
|
+
- spec/unit/knight/rule/format/to_hash_spec.rb
|
98
|
+
- spec/unit/knight/rule/inclusion/class_methods/new_spec.rb
|
99
|
+
- spec/unit/knight/rule/inclusion/matches_predicate_spec.rb
|
100
|
+
- spec/unit/knight/rule/inclusion/to_hash_spec.rb
|
101
|
+
- spec/unit/knight/rule/maximum_length/class_methods/new_spec.rb
|
102
|
+
- spec/unit/knight/rule/maximum_length/matches_predicate_spec.rb
|
103
|
+
- spec/unit/knight/rule/maximum_length/to_hash_spec.rb
|
104
|
+
- spec/unit/knight/rule/minimum_length/class_methods/new_spec.rb
|
105
|
+
- spec/unit/knight/rule/minimum_length/matches_predicate_spec.rb
|
106
|
+
- spec/unit/knight/rule/minimum_length/to_hash_spec.rb
|
107
|
+
- spec/unit/knight/rule/presence/matches_predicate_spec.rb
|
108
|
+
- spec/unit/knight/rule/range_length/class_methods/new_spec.rb
|
109
|
+
- spec/unit/knight/rule/range_length/matches_predicate_spec.rb
|
110
|
+
- spec/unit/knight/rule/range_length/to_hash_spec.rb
|
111
|
+
- spec/unit/knight/rule/to_hash_spec.rb
|
112
|
+
- spec/unit/knight/validator/add_spec.rb
|
113
|
+
- spec/unit/knight/validator/class_methods/new_spec.rb
|
114
|
+
- spec/unit/knight/validator/context_spec.rb
|
115
|
+
- spec/unit/knight/validator/rules_spec.rb
|
116
|
+
- spec/unit/knight/validator/run_spec.rb
|
29
117
|
homepage: ''
|
30
118
|
licenses: []
|
31
119
|
post_install_message:
|
@@ -36,12 +124,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
124
|
requirements:
|
37
125
|
- - ! '>='
|
38
126
|
- !ruby/object:Gem::Version
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
hash: 2891558261604624583
|
39
130
|
version: '0'
|
40
131
|
none: false
|
41
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
133
|
requirements:
|
43
134
|
- - ! '>='
|
44
135
|
- !ruby/object:Gem::Version
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
hash: 2891558261604624583
|
45
139
|
version: '0'
|
46
140
|
none: false
|
47
141
|
requirements: []
|
@@ -50,5 +144,43 @@ rubygems_version: 1.8.23
|
|
50
144
|
signing_key:
|
51
145
|
specification_version: 3
|
52
146
|
summary: ''
|
53
|
-
test_files:
|
54
|
-
|
147
|
+
test_files:
|
148
|
+
- spec/integration/contextual_validator_spec.rb
|
149
|
+
- spec/integration/knight_spec.rb
|
150
|
+
- spec/spec_helper.rb
|
151
|
+
- spec/unit/knight/error/class_methods/new_spec.rb
|
152
|
+
- spec/unit/knight/error/message_spec.rb
|
153
|
+
- spec/unit/knight/instance_methods/class_methods/included_spec.rb
|
154
|
+
- spec/unit/knight/instance_methods/class_methods/new_spec.rb
|
155
|
+
- spec/unit/knight/instance_methods/class_methods/validator_spec.rb
|
156
|
+
- spec/unit/knight/instance_methods/run_spec.rb
|
157
|
+
- spec/unit/knight/result/class_methods/new_spec.rb
|
158
|
+
- spec/unit/knight/result/errors_spec.rb
|
159
|
+
- spec/unit/knight/result/valid_predicate_spec.rb
|
160
|
+
- spec/unit/knight/rule/class_methods/new_spec.rb
|
161
|
+
- spec/unit/knight/rule/error_spec.rb
|
162
|
+
- spec/unit/knight/rule/exact_length/class_methods/new_spec.rb
|
163
|
+
- spec/unit/knight/rule/exact_length/matches_predicate_spec.rb
|
164
|
+
- spec/unit/knight/rule/exact_length/to_hash_spec.rb
|
165
|
+
- spec/unit/knight/rule/format/class_methods/new_spec.rb
|
166
|
+
- spec/unit/knight/rule/format/matches_predicate_spec.rb
|
167
|
+
- spec/unit/knight/rule/format/to_hash_spec.rb
|
168
|
+
- spec/unit/knight/rule/inclusion/class_methods/new_spec.rb
|
169
|
+
- spec/unit/knight/rule/inclusion/matches_predicate_spec.rb
|
170
|
+
- spec/unit/knight/rule/inclusion/to_hash_spec.rb
|
171
|
+
- spec/unit/knight/rule/maximum_length/class_methods/new_spec.rb
|
172
|
+
- spec/unit/knight/rule/maximum_length/matches_predicate_spec.rb
|
173
|
+
- spec/unit/knight/rule/maximum_length/to_hash_spec.rb
|
174
|
+
- spec/unit/knight/rule/minimum_length/class_methods/new_spec.rb
|
175
|
+
- spec/unit/knight/rule/minimum_length/matches_predicate_spec.rb
|
176
|
+
- spec/unit/knight/rule/minimum_length/to_hash_spec.rb
|
177
|
+
- spec/unit/knight/rule/presence/matches_predicate_spec.rb
|
178
|
+
- spec/unit/knight/rule/range_length/class_methods/new_spec.rb
|
179
|
+
- spec/unit/knight/rule/range_length/matches_predicate_spec.rb
|
180
|
+
- spec/unit/knight/rule/range_length/to_hash_spec.rb
|
181
|
+
- spec/unit/knight/rule/to_hash_spec.rb
|
182
|
+
- spec/unit/knight/validator/add_spec.rb
|
183
|
+
- spec/unit/knight/validator/class_methods/new_spec.rb
|
184
|
+
- spec/unit/knight/validator/context_spec.rb
|
185
|
+
- spec/unit/knight/validator/rules_spec.rb
|
186
|
+
- spec/unit/knight/validator/run_spec.rb
|