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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a761bddc4060235798798e1a3b7001e7e8fc902285f01acf79b76bb31864e9e
4
- data.tar.gz: 654e5b1c3172279542b10287b06012d18dec61a5bdd3effbebf28da828a0c198
3
+ metadata.gz: c5d480d4df733d8f1ad93140a811d2d5b63b393b822f705ceca2471e370fea1d
4
+ data.tar.gz: a7aabbfa2758f6f34792f54947c6d867ddd593f3f0e6a3b3871fff94861b5c36
5
5
  SHA512:
6
- metadata.gz: 63ce5b912ecf04f716a319eab43ca3434619bc4d6c330da8522a2c23db06f0f3d9e6c74e8005d9a7d88c65c9e76016cec7a04637353c124c7e46e3a90612a5c8
7
- data.tar.gz: c7a11cb8f47b9e10d9023b432433ae574e6e8be67b6e29d73e48a3ac202eb76bc218dc3d13caff0cb579377dd22a846d1323487da2b9afd4e943fff4d34508fc
6
+ metadata.gz: 3f9576162a2267d725a41517dc915d4ae4b3fec1e5bef950eb862672efa336daa3eafa5566cffda2c9fdb07df1a14b4d63548cbe5c8a4827d09588977f06dd4e
7
+ data.tar.gz: 4e31bf387b63acce85711d14a83697092d5f09a3adb1b7c78bffbb7c82ad59fd137ff25e03926bb47b627a91428b6385cb0467ba104771c1b5d301c336dcb825
@@ -6,3 +6,6 @@ Metrics/MethodLength:
6
6
 
7
7
  Metrics/LineLength:
8
8
  Max: 120
9
+
10
+ Style/Documentation:
11
+ Enabled: false
@@ -8,6 +8,7 @@ notifications:
8
8
  script:
9
9
  - bundle exec rake rubocop
10
10
  - bundle exec rake spec
11
+ - bundle exec yard doc --fail-on-warning
11
12
 
12
13
  after_success:
13
14
  - bundle exec codeclimate-test-reporter
@@ -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
@@ -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', '~> 10.0'
28
- spec.add_development_dependency 'rspec', '~> 3.0'
29
- spec.add_development_dependency 'rubocop', '~> 0.58'
30
- spec.add_development_dependency 'rubocop-rspec', '~> 1.29'
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
@@ -27,7 +27,7 @@ require 'active_interactor/version'
27
27
  module ActiveInteractor
28
28
  extend ActiveSupport::Concern
29
29
 
30
- class_methods do
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
- validator = self.class.validator_class.new
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
- @errors = validate(params)
119
- super(params) if @errors.empty?
116
+ validate(params)
117
+ super(params) if errors.empty?
120
118
  end
121
119
 
122
- Result.new(result_payload, @errors)
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
- private # rubocop:disable Lint/UselessAccessModifier
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 args [Hash]
193
- # @return [ActiveModel::Errors]
200
+ # @param params [Hash]
201
+ # @return [void]
194
202
  def validate(params)
195
- validator = self.class.validator_class.new
196
- if self.class.validation_required?
197
- validator.assign_attributes(params)
198
- validator.valid?
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]
@@ -1,3 +1,3 @@
1
1
  module ActiveInteractor
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
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.1.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-09-03 00:00:00.000000000 Z
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: '10.0'
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: '10.0'
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.0'
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.0'
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: '0.58'
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: '0.58'
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.29'
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.29'
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