use_case_pattern 1.0.1 → 1.0.4
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.
- checksums.yaml +5 -5
- data/.travis.yml +7 -3
- data/CHANGELOG.md +14 -0
- data/README.md +1 -1
- data/lib/use_case_pattern/base.rb +38 -7
- data/lib/use_case_pattern/version.rb +1 -1
- data/use_case_pattern.gemspec +2 -2
- metadata +12 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fc01a949d6793118c4df7e91e3f93e5e2ac8720b439038a27e7da7ca28ba2449
|
4
|
+
data.tar.gz: 73cd64bf8effb9cd3b6928aa4fb94e091b30abb2845fadf1f4e46693dd4710e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fef8c351e4569ea4f85878c9a6f7da745bbf83bfb646cd2f1f06310c60f9f38e969740a7d9f446387fe93a41e29701e12bf1d3a60c075f06bd6d8578d0f90bf7
|
7
|
+
data.tar.gz: 33206b819c01e1a69868ad6fb0b47985913b0a59e44c8f2b883aee768e13b91bd8c97935754a326ed668bd047f0bb635832c39e8aa043539824ff275896ca043
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# AddressFinder 1.0.4 (Aug 8, 2022)
|
2
|
+
|
3
|
+
* Add support for Ruby 3
|
4
|
+
# AddressFinder 1.0.3 (May 27, 2020)
|
5
|
+
|
6
|
+
* Add support for Ruby 2.7
|
7
|
+
* Drop support for Ruby 2.2
|
8
|
+
* Ruby 2.7 deprecated the use of hashes in the last argument of a method call. We added a check to handle that deprecation. Read more here: https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
|
9
|
+
|
10
|
+
# AddressFinder 1.0.2 (November 22, 2016) #
|
11
|
+
|
12
|
+
* Raise a ValidationError when #perform! fails rather that call the Rails 5
|
13
|
+
specific #raise_validation_error method
|
14
|
+
|
1
15
|
# AddressFinder 1.0.1 (October 12, 2016) #
|
2
16
|
|
3
17
|
* Declare support for activemodel/activesupport version 4.0 or better
|
data/README.md
CHANGED
@@ -97,7 +97,7 @@ The caller can check the success or failure of the use case by calling the `succ
|
|
97
97
|
|
98
98
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
99
99
|
|
100
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
100
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, update `CHANGELOG.md`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
101
101
|
|
102
102
|
## Contributing
|
103
103
|
|
@@ -9,7 +9,7 @@ module UseCasePattern
|
|
9
9
|
module ClassMethods
|
10
10
|
# The perform method of a UseCase should always return itself
|
11
11
|
def perform(*args)
|
12
|
-
|
12
|
+
use_case(*args).tap do |use_case|
|
13
13
|
if use_case.valid?
|
14
14
|
use_case.perform
|
15
15
|
end
|
@@ -18,7 +18,20 @@ module UseCasePattern
|
|
18
18
|
|
19
19
|
# Raise a validation error if perform has created any errors
|
20
20
|
def perform!(*args)
|
21
|
-
|
21
|
+
use_case(*args).tap { |use_case| use_case.perform! }
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# initialises the use_case, making sure that any keyword arguments are
|
27
|
+
# dealt with appropriately: https://piechowski.io/post/last-arg-keyword-deprecated-ruby-2-7/
|
28
|
+
def use_case(*args)
|
29
|
+
if args.last.is_a?(Hash)
|
30
|
+
keyword_arguments = args.pop
|
31
|
+
new(*args, **keyword_arguments)
|
32
|
+
else
|
33
|
+
new(*args)
|
34
|
+
end
|
22
35
|
end
|
23
36
|
end
|
24
37
|
|
@@ -28,13 +41,11 @@ module UseCasePattern
|
|
28
41
|
end
|
29
42
|
|
30
43
|
def perform!
|
31
|
-
if
|
32
|
-
|
44
|
+
if invalid?
|
45
|
+
raise(ValidationError.new(self))
|
33
46
|
end
|
34
47
|
|
35
|
-
|
36
|
-
raise_validation_error
|
37
|
-
end
|
48
|
+
perform
|
38
49
|
end
|
39
50
|
|
40
51
|
# Did the use case performed its task without errors?
|
@@ -47,4 +58,24 @@ module UseCasePattern
|
|
47
58
|
errors.any?
|
48
59
|
end
|
49
60
|
end
|
61
|
+
|
62
|
+
# Use Case Pattern ValidationError
|
63
|
+
#
|
64
|
+
# Raised by <tt>perform!</tt> when validations result in errors.
|
65
|
+
#
|
66
|
+
# Check the use case +errors+ object for attribute error messages.
|
67
|
+
#
|
68
|
+
# ActiveModel 5.0 has an ActiveModel::ValidationError class, prior versions including 4.2 do not.
|
69
|
+
#
|
70
|
+
# This class may be deprecated by ActiveModel::ValidationError in the future.
|
71
|
+
#
|
72
|
+
class ValidationError < StandardError
|
73
|
+
attr_reader :model
|
74
|
+
|
75
|
+
def initialize(model)
|
76
|
+
@model = model
|
77
|
+
errors = @model.errors.full_messages.join(", ")
|
78
|
+
super("Validation failed: " + errors)
|
79
|
+
end
|
80
|
+
end
|
50
81
|
end
|
data/use_case_pattern.gemspec
CHANGED
@@ -20,12 +20,12 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.required_ruby_version = '
|
23
|
+
spec.required_ruby_version = '>= 2.3'
|
24
24
|
|
25
25
|
spec.add_runtime_dependency "activemodel", [">= 4.0.0"]
|
26
26
|
spec.add_runtime_dependency "activesupport", [">= 4.0.0"]
|
27
27
|
|
28
|
-
spec.add_development_dependency "bundler", "
|
28
|
+
spec.add_development_dependency "bundler", ">= 2.1.4"
|
29
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
30
30
|
spec.add_development_dependency "rspec", "~> 3.0"
|
31
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: use_case_pattern
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nigel Ramsay
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 2.1.4
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 2.1.4
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,24 +106,23 @@ files:
|
|
106
106
|
homepage: https://github.com/abletech/use_case_pattern
|
107
107
|
licenses: []
|
108
108
|
metadata: {}
|
109
|
-
post_install_message:
|
109
|
+
post_install_message:
|
110
110
|
rdoc_options: []
|
111
111
|
require_paths:
|
112
112
|
- lib
|
113
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '2.
|
117
|
+
version: '2.3'
|
118
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
119
|
requirements:
|
120
120
|
- - ">="
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: '0'
|
123
123
|
requirements: []
|
124
|
-
|
125
|
-
|
126
|
-
signing_key:
|
124
|
+
rubygems_version: 3.2.3
|
125
|
+
signing_key:
|
127
126
|
specification_version: 4
|
128
127
|
summary: A module that helps you to implement the Use Case design pattern
|
129
128
|
test_files: []
|