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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Yzg4YWJiZjk3M2FhODgyNDUxNWQxY2ZhZDExNDk0ZTIyZWFmMWYxNw==
4
+ YTMxZGE1YmE0MzAxZDM2OTM0M2E4NWU3NTZhMGU4ODhkNjM5MTE1OQ==
5
5
  data.tar.gz: !binary |-
6
- OGEyOWQ5MmMxMGU1MTRhMzUxNTQ3MTNlNDczZmYyMDAxMWM4MDVhYg==
6
+ OTQwYzIzZTEwYTAxMjY0ZjQzMTdkZDhmZjU2MDgyMTBkMTY0ZTU1Yw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjIxOTc5NWQ4ODE4MDUzMzUyN2M2OTZjMjM0M2U2ODhkMDY5YjZlNjE4NzE0
10
- YmE3MzdhMTNmZjIwOGNlMDAxOThkNGUxNjBhNjc1MDcyZTgwODNjYjBlNTQ4
11
- YzFmMmY4ZjRkYjU2MmZkNTdmYmU1YTY3YTRiODE3M2ZjOTQ4Mzc=
9
+ YTYyMGM4OTJlYjhhYjEwZWM4M2EyN2FjMzg0NWNhMjQzNDU4MTM3YjBlYzhj
10
+ MjAwZTY2NWQwMzNlYmE2YjAzNjA4ZjNjYzcxZTRkOWJjMjE2YjA4NzI5YzM4
11
+ YWUzYmM3NGVlNGYyNDlhNWY1OTA1MDY4MjQ5OGU0ZDU4YzI2YTI=
12
12
  data.tar.gz: !binary |-
13
- NzEyN2NiZDI3NDM5MDMwNjJlNWVlNmNiYjdiZTVjYTc4NWY5MjhjNzUzNzUz
14
- ZmUwOGZiOGUxMzU3ZTc0M2Q3NTI4ZWY4YmZhYjliMzZlYjFlMTlmYjAzOTJl
15
- YzgyNWZlNjUzNzM0NzI0ZWMxYTc1YjM3ZjYwODgyOWRhYzgzZmY=
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,5 +1,5 @@
1
1
  module UseCaseValidations
2
-
2
+
3
3
  module Helpers
4
4
 
5
5
  extend self
@@ -1,3 +1,3 @@
1
1
  module UseCaseValidations
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.3"
3
3
  end
@@ -16,7 +16,7 @@ module Group
16
16
 
17
17
  end
18
18
 
19
- class ValidateDependsAll < UseCase::Base
19
+ class ValidateAll < UseCase::GroupValidator
20
20
 
21
21
  depends_all ValidatePostTitle, ValidatePostBody
22
22
 
@@ -1,18 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Group::ValidateDependsAll do
3
+ describe Group::ValidateAll do
4
4
 
5
- it "Validating multiple UseCase:Validators at the same time without one interrupting the other", current: true do
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::ValidateDependsAll.perform(post: post)
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::ValidateDependsAll.perform(post: post2)
15
+ context = Group::ValidateAll.perform(post: post2)
16
16
  context.success?.should == true
17
17
  post2.errors.empty?.should == true
18
18
 
@@ -24,6 +24,6 @@ Gem::Specification.new do |gem|
24
24
  gem.add_development_dependency "mocha"
25
25
  gem.add_development_dependency "pry"
26
26
 
27
- gem.add_runtime_dependency 'usecasing', '0.1.4'
27
+ gem.add_runtime_dependency 'usecasing'
28
28
 
29
29
  end
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.1
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-02-02 00:00:00.000000000 Z
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.1.4
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.1.4
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/validate_depends_all.rb
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/validate_depends_all_spec.rb
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/validate_depends_all.rb
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/validate_depends_all_spec.rb
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