active_interactor 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +19 -0
- data/active_interactor.gemspec +5 -4
- data/lib/active_interactor.rb +23 -16
- data/lib/active_interactor/version.rb +1 -1
- metadata +25 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5d480d4df733d8f1ad93140a811d2d5b63b393b822f705ceca2471e370fea1d
|
4
|
+
data.tar.gz: a7aabbfa2758f6f34792f54947c6d867ddd593f3f0e6a3b3871fff94861b5c36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f9576162a2267d725a41517dc915d4ae4b3fec1e5bef950eb862672efa336daa3eafa5566cffda2c9fdb07df1a14b4d63548cbe5c8a4827d09588977f06dd4e
|
7
|
+
data.tar.gz: 4e31bf387b63acce85711d14a83697092d5f09a3adb1b7c78bffbb7c82ad59fd137ff25e03926bb47b627a91428b6385cb0467ba104771c1b5d301c336dcb825
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
This change log adheres to [keepachangelog.com](http://keepachangelog.com).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## [0.2.0] - 2018-10-24
|
10
|
+
### Added
|
11
|
+
- Enable to access validator instance in `#call` method.
|
12
|
+
- Use yard.
|
13
|
+
|
14
|
+
## [0.1.0] - 2018-09-03
|
15
|
+
- Initial release.
|
16
|
+
|
17
|
+
[Unreleased]: https://github.com/increments/active_interactor/compare/v0.2.0...HEAD
|
18
|
+
[0.2.0]: https://github.com/increments/active_interactor/compare/v0.1.0...v0.2.0
|
19
|
+
[0.1.0]: https://github.com/increments/active_interactor/compare/7de7624...v0.1.0
|
data/active_interactor.gemspec
CHANGED
@@ -24,9 +24,10 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
26
26
|
spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
|
27
|
-
spec.add_development_dependency 'rake', '~>
|
28
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
29
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
30
|
-
spec.add_development_dependency 'rubocop-rspec', '~> 1.
|
27
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.8'
|
29
|
+
spec.add_development_dependency 'rubocop', '~> 0.59.2'
|
30
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.30'
|
31
31
|
spec.add_development_dependency 'simplecov', '~> 0.16.1'
|
32
|
+
spec.add_development_dependency 'yard', '~> 0.9.16'
|
32
33
|
end
|
data/lib/active_interactor.rb
CHANGED
@@ -27,7 +27,7 @@ require 'active_interactor/version'
|
|
27
27
|
module ActiveInteractor
|
28
28
|
extend ActiveSupport::Concern
|
29
29
|
|
30
|
-
|
30
|
+
module ClassMethods
|
31
31
|
# Configure {.validator_class}
|
32
32
|
#
|
33
33
|
# @param attribute_names [Array<Symbol>] list of
|
@@ -94,7 +94,6 @@ module ActiveInteractor
|
|
94
94
|
|
95
95
|
included do
|
96
96
|
prepend ActiveInteractor::Interface
|
97
|
-
attr_reader :errors
|
98
97
|
end
|
99
98
|
|
100
99
|
# Interactor interface.
|
@@ -108,18 +107,17 @@ module ActiveInteractor
|
|
108
107
|
raise ArgumentError if args.size == 1 && !args.first.is_a?(Hash)
|
109
108
|
|
110
109
|
params = args.extract_options!
|
111
|
-
|
110
|
+
errors.clear
|
112
111
|
|
113
112
|
if params.empty? && !self.class.validation_required?
|
114
|
-
@errors = validator.errors
|
115
113
|
super
|
116
114
|
else
|
117
115
|
params = sanitize(params)
|
118
|
-
|
119
|
-
super(params) if
|
116
|
+
validate(params)
|
117
|
+
super(params) if errors.empty?
|
120
118
|
end
|
121
119
|
|
122
|
-
Result.new(result_payload,
|
120
|
+
Result.new(result_payload, errors)
|
123
121
|
end
|
124
122
|
|
125
123
|
# rubocop:enable all
|
@@ -168,6 +166,11 @@ module ActiveInteractor
|
|
168
166
|
raise NotImplementedError
|
169
167
|
end
|
170
168
|
|
169
|
+
# @return [ActiveModel::Errors]
|
170
|
+
def errors
|
171
|
+
validator.errors
|
172
|
+
end
|
173
|
+
|
171
174
|
# Merge the given errors into {#errors}.
|
172
175
|
#
|
173
176
|
# @param additional_errors [ActiveModel::Errors]
|
@@ -178,7 +181,12 @@ module ActiveInteractor
|
|
178
181
|
end
|
179
182
|
end
|
180
183
|
|
181
|
-
|
184
|
+
# @return [ActiveModel::Validations] an instance of {ActiveInteractor::ClassMethods#validator_class}
|
185
|
+
def validator
|
186
|
+
@validator ||= self.class.validator_class.new
|
187
|
+
end
|
188
|
+
|
189
|
+
private
|
182
190
|
|
183
191
|
# @return [Hash] a hash representing a payload for {ActiveInteractor::Result}
|
184
192
|
def result_payload
|
@@ -189,15 +197,13 @@ module ActiveInteractor
|
|
189
197
|
end
|
190
198
|
end
|
191
199
|
|
192
|
-
# @param
|
193
|
-
# @return [
|
200
|
+
# @param params [Hash]
|
201
|
+
# @return [void]
|
194
202
|
def validate(params)
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
end
|
200
|
-
validator.errors
|
203
|
+
return unless self.class.validation_required?
|
204
|
+
|
205
|
+
validator.assign_attributes(params)
|
206
|
+
validator.valid?
|
201
207
|
end
|
202
208
|
|
203
209
|
# Remove undeclared keys from the given params.
|
@@ -206,6 +212,7 @@ module ActiveInteractor
|
|
206
212
|
# @return [Hash]
|
207
213
|
def sanitize(params)
|
208
214
|
return params unless self.class.validation_required?
|
215
|
+
|
209
216
|
Hash[].tap do |result|
|
210
217
|
self.class.validation_attribute_names.each do |name|
|
211
218
|
result[name] = params[name]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_interactor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuku TAKAHASHI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -72,56 +72,56 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '12.3'
|
76
76
|
type: :development
|
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: '
|
82
|
+
version: '12.3'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '3.
|
89
|
+
version: '3.8'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '3.
|
96
|
+
version: '3.8'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rubocop
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 0.59.2
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 0.59.2
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rubocop-rspec
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '1.
|
117
|
+
version: '1.30'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '1.
|
124
|
+
version: '1.30'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: simplecov
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: 0.16.1
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: yard
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.9.16
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.9.16
|
139
153
|
description:
|
140
154
|
email:
|
141
155
|
- yuku@qiita.com
|
@@ -147,6 +161,7 @@ files:
|
|
147
161
|
- ".rspec"
|
148
162
|
- ".rubocop.yml"
|
149
163
|
- ".travis.yml"
|
164
|
+
- CHANGELOG.md
|
150
165
|
- CODE_OF_CONDUCT.md
|
151
166
|
- Gemfile
|
152
167
|
- LICENSE.txt
|