knight 0.0.1 → 0.0.2

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.
Files changed (64) hide show
  1. data/.gitignore +1 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +9 -0
  4. data/Gemfile +7 -0
  5. data/Gemfile.dev +16 -0
  6. data/README.md +3 -1
  7. data/Rakefile +6 -1
  8. data/knight.gemspec +4 -1
  9. data/lib/knight.rb +18 -2
  10. data/lib/knight/error.rb +60 -0
  11. data/lib/knight/instance_methods.rb +69 -0
  12. data/lib/knight/result.rb +86 -0
  13. data/lib/knight/rule.rb +74 -0
  14. data/lib/knight/rule/exact_length.rb +63 -0
  15. data/lib/knight/rule/format.rb +62 -0
  16. data/lib/knight/rule/inclusion.rb +62 -0
  17. data/lib/knight/rule/maximum_length.rb +63 -0
  18. data/lib/knight/rule/minimum_length.rb +63 -0
  19. data/lib/knight/rule/presence.rb +37 -0
  20. data/lib/knight/rule/range_length.rb +64 -0
  21. data/lib/knight/validator.rb +91 -0
  22. data/lib/knight/version.rb +3 -1
  23. data/metrics/flog.yml +2 -0
  24. data/metrics/rubocop.yml +17 -0
  25. data/spec/integration/contextual_validator_spec.rb +41 -0
  26. data/spec/integration/knight_spec.rb +30 -0
  27. data/spec/spec_helper.rb +18 -0
  28. data/spec/unit/knight/error/class_methods/new_spec.rb +15 -0
  29. data/spec/unit/knight/error/message_spec.rb +26 -0
  30. data/spec/unit/knight/instance_methods/class_methods/included_spec.rb +24 -0
  31. data/spec/unit/knight/instance_methods/class_methods/new_spec.rb +12 -0
  32. data/spec/unit/knight/instance_methods/class_methods/validator_spec.rb +13 -0
  33. data/spec/unit/knight/instance_methods/run_spec.rb +29 -0
  34. data/spec/unit/knight/result/class_methods/new_spec.rb +13 -0
  35. data/spec/unit/knight/result/errors_spec.rb +71 -0
  36. data/spec/unit/knight/result/valid_predicate_spec.rb +28 -0
  37. data/spec/unit/knight/rule/class_methods/new_spec.rb +38 -0
  38. data/spec/unit/knight/rule/error_spec.rb +29 -0
  39. data/spec/unit/knight/rule/exact_length/class_methods/new_spec.rb +27 -0
  40. data/spec/unit/knight/rule/exact_length/matches_predicate_spec.rb +19 -0
  41. data/spec/unit/knight/rule/exact_length/to_hash_spec.rb +12 -0
  42. data/spec/unit/knight/rule/format/class_methods/new_spec.rb +26 -0
  43. data/spec/unit/knight/rule/format/matches_predicate_spec.rb +31 -0
  44. data/spec/unit/knight/rule/format/to_hash_spec.rb +12 -0
  45. data/spec/unit/knight/rule/inclusion/class_methods/new_spec.rb +28 -0
  46. data/spec/unit/knight/rule/inclusion/matches_predicate_spec.rb +48 -0
  47. data/spec/unit/knight/rule/inclusion/to_hash_spec.rb +12 -0
  48. data/spec/unit/knight/rule/maximum_length/class_methods/new_spec.rb +27 -0
  49. data/spec/unit/knight/rule/maximum_length/matches_predicate_spec.rb +21 -0
  50. data/spec/unit/knight/rule/maximum_length/to_hash_spec.rb +12 -0
  51. data/spec/unit/knight/rule/minimum_length/class_methods/new_spec.rb +27 -0
  52. data/spec/unit/knight/rule/minimum_length/matches_predicate_spec.rb +21 -0
  53. data/spec/unit/knight/rule/minimum_length/to_hash_spec.rb +12 -0
  54. data/spec/unit/knight/rule/presence/matches_predicate_spec.rb +27 -0
  55. data/spec/unit/knight/rule/range_length/class_methods/new_spec.rb +27 -0
  56. data/spec/unit/knight/rule/range_length/matches_predicate_spec.rb +19 -0
  57. data/spec/unit/knight/rule/range_length/to_hash_spec.rb +12 -0
  58. data/spec/unit/knight/rule/to_hash_spec.rb +13 -0
  59. data/spec/unit/knight/validator/add_spec.rb +29 -0
  60. data/spec/unit/knight/validator/class_methods/new_spec.rb +18 -0
  61. data/spec/unit/knight/validator/context_spec.rb +13 -0
  62. data/spec/unit/knight/validator/rules_spec.rb +29 -0
  63. data/spec/unit/knight/validator/run_spec.rb +26 -0
  64. 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.1
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-27 00:00:00.000000000 Z
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
- - handi@domikado.com
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
- has_rdoc:
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