usecasing_validations 0.5.1 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/usecasing/group_validator.rb +34 -0
- data/lib/usecasing_validations.rb +1 -31
- data/lib/usecasing_validations/helpers.rb +1 -1
- data/lib/usecasing_validations/version.rb +1 -1
- data/spec/support/usecases/{validate_depends_all.rb → validate_group_validator.rb} +1 -1
- data/spec/usecasing/{validate_depends_all_spec.rb → validate_group_validator_spec.rb} +4 -4
- data/usecasing_validations.gemspec +1 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTMxZGE1YmE0MzAxZDM2OTM0M2E4NWU3NTZhMGU4ODhkNjM5MTE1OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTQwYzIzZTEwYTAxMjY0ZjQzMTdkZDhmZjU2MDgyMTBkMTY0ZTU1Yw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTYyMGM4OTJlYjhhYjEwZWM4M2EyN2FjMzg0NWNhMjQzNDU4MTM3YjBlYzhj
|
10
|
+
MjAwZTY2NWQwMzNlYmE2YjAzNjA4ZjNjYzcxZTRkOWJjMjE2YjA4NzI5YzM4
|
11
|
+
YWUzYmM3NGVlNGYyNDlhNWY1OTA1MDY4MjQ5OGU0ZDU4YzI2YTI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjEzYzRiOGVjYTA2YmJmYTNhNGZjNGY3MmJkYmY4ZDQxNWJjMjM4Y2IwNjhk
|
14
|
+
MWQ5MmVmYWI5NzJmYTQzYTRhNzM4NTY5YWI5MzcyY2YwZmEzOGM4ZWRkZmIz
|
15
|
+
MjAwZjgxNzY0YzRkOGY3MWIwZjAyYzI1ZjBhMjRjOGM5Y2M2ZmY=
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module UseCase
|
2
|
+
|
3
|
+
class GroupValidator < Base
|
4
|
+
|
5
|
+
def perform
|
6
|
+
usecases_vs_results = {}
|
7
|
+
|
8
|
+
self.class.group_dependencies.each do |usecase|
|
9
|
+
usecases_vs_results[usecase.to_s] = usecase.perform(context_to_hash).success?
|
10
|
+
end
|
11
|
+
|
12
|
+
usecases_vs_results.each do |usecase_name, result|
|
13
|
+
failure(usecase_name, :failed) unless result
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.depends_all(*new_dependencies)
|
18
|
+
group_dependencies.push(*new_dependencies)
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
protected ####################### PROTECTED #################
|
23
|
+
|
24
|
+
def context_to_hash
|
25
|
+
context.instance_variable_get('@values')
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.group_dependencies
|
29
|
+
@group_dependencies ||= []
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -15,38 +15,8 @@ require "usecasing_validations/validations/uniqueness"
|
|
15
15
|
|
16
16
|
|
17
17
|
module UseCase
|
18
|
-
|
19
|
-
class Base
|
20
|
-
|
21
|
-
def self.depends_all(*deps)
|
22
|
-
@dependencies ||= []
|
23
|
-
@dependencies.push(*deps)
|
24
|
-
ignored_dependencies.push(*deps)
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.ignored_dependencies
|
28
|
-
@ignored_dependencies ||= []
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.not_ignored(usecase)
|
32
|
-
!ignored_dependencies.include?(usecase)
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.tx(execution_order, context)
|
36
|
-
ctx = Context.new(context)
|
37
|
-
executed = []
|
38
|
-
execution_order.each do |usecase|
|
39
|
-
break if not_ignored(usecase) && !ctx.success?
|
40
|
-
executed.push(usecase)
|
41
|
-
yield usecase, ctx
|
42
|
-
end
|
43
|
-
rollback(executed, ctx) unless ctx.success?
|
44
|
-
ctx
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
18
|
autoload :Validator, 'usecasing/validator'
|
19
|
+
autoload :GroupValidator, 'usecasing/group_validator'
|
50
20
|
end
|
51
21
|
|
52
22
|
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Group::
|
3
|
+
describe Group::ValidateAll do
|
4
4
|
|
5
|
-
it "Validating multiple UseCase:Validators at the same time without one interrupting the other"
|
5
|
+
it "Validating multiple UseCase:Validators at the same time without one interrupting the other" do
|
6
6
|
|
7
7
|
post = RubyPost.new
|
8
|
-
context = Group::
|
8
|
+
context = Group::ValidateAll.perform(post: post)
|
9
9
|
context.success?.should == false
|
10
10
|
post.errors.added?(:title, :blank).should == true
|
11
11
|
post.errors.added?(:body, :blank).should == true
|
12
12
|
post.errors.size.should == 2
|
13
13
|
|
14
14
|
post2 = RubyPost.new(title: 'title', body: 'body')
|
15
|
-
context = Group::
|
15
|
+
context = Group::ValidateAll.perform(post: post2)
|
16
16
|
context.success?.should == true
|
17
17
|
post2.errors.empty?.should == true
|
18
18
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usecasing_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- João Gonçalves
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: usecasing
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - '
|
73
|
+
- - ! '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0
|
75
|
+
version: '0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - '
|
80
|
+
- - ! '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0
|
82
|
+
version: '0'
|
83
83
|
description: UseCase Gem Extention to add Rails like validations
|
84
84
|
email:
|
85
85
|
- goncalves.joao@gmail.com
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- LICENSE.txt
|
96
96
|
- README.md
|
97
97
|
- Rakefile
|
98
|
+
- lib/usecasing/group_validator.rb
|
98
99
|
- lib/usecasing/validator.rb
|
99
100
|
- lib/usecasing_validations.rb
|
100
101
|
- lib/usecasing_validations/custom_validator.rb
|
@@ -114,13 +115,13 @@ files:
|
|
114
115
|
- spec/support/models/ruby_post_with_comments.rb
|
115
116
|
- spec/support/usecases/validate_comments.rb
|
116
117
|
- spec/support/usecases/validate_comments_custom_target.rb
|
117
|
-
- spec/support/usecases/
|
118
|
+
- spec/support/usecases/validate_group_validator.rb
|
118
119
|
- spec/support/usecases/validate_post.rb
|
119
120
|
- spec/support/usecases/validate_post_clear_errors.rb
|
120
121
|
- spec/support/usecases/validate_uniq_comments.rb
|
121
122
|
- spec/usecasing/validate_comments_custom_target_spec.rb
|
122
123
|
- spec/usecasing/validate_comments_spec.rb
|
123
|
-
- spec/usecasing/
|
124
|
+
- spec/usecasing/validate_group_validator_spec.rb
|
124
125
|
- spec/usecasing/validate_post_clear_errors_spec.rb
|
125
126
|
- spec/usecasing/validates_uniqueness_of_spec.rb
|
126
127
|
- usecasing_validations.gemspec
|
@@ -154,12 +155,12 @@ test_files:
|
|
154
155
|
- spec/support/models/ruby_post_with_comments.rb
|
155
156
|
- spec/support/usecases/validate_comments.rb
|
156
157
|
- spec/support/usecases/validate_comments_custom_target.rb
|
157
|
-
- spec/support/usecases/
|
158
|
+
- spec/support/usecases/validate_group_validator.rb
|
158
159
|
- spec/support/usecases/validate_post.rb
|
159
160
|
- spec/support/usecases/validate_post_clear_errors.rb
|
160
161
|
- spec/support/usecases/validate_uniq_comments.rb
|
161
162
|
- spec/usecasing/validate_comments_custom_target_spec.rb
|
162
163
|
- spec/usecasing/validate_comments_spec.rb
|
163
|
-
- spec/usecasing/
|
164
|
+
- spec/usecasing/validate_group_validator_spec.rb
|
164
165
|
- spec/usecasing/validate_post_clear_errors_spec.rb
|
165
166
|
- spec/usecasing/validates_uniqueness_of_spec.rb
|