active_interaction 1.4.1 → 2.0.0

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +65 -3
  3. data/CONTRIBUTING.md +19 -0
  4. data/README.md +1121 -180
  5. data/lib/active_interaction/backports.rb +58 -13
  6. data/lib/active_interaction/base.rb +16 -52
  7. data/lib/active_interaction/concerns/active_recordable.rb +57 -0
  8. data/lib/active_interaction/concerns/runnable.rb +4 -14
  9. data/lib/active_interaction/errors.rb +14 -66
  10. data/lib/active_interaction/filters/array_filter.rb +12 -9
  11. data/lib/active_interaction/filters/file_filter.rb +5 -24
  12. data/lib/active_interaction/filters/hash_filter.rb +11 -13
  13. data/lib/active_interaction/filters/interface_filter.rb +2 -2
  14. data/lib/active_interaction/filters/{model_filter.rb → object_filter.rb} +6 -6
  15. data/lib/active_interaction/locale/en.yml +1 -1
  16. data/lib/active_interaction/modules/validation.rb +2 -2
  17. data/lib/active_interaction/version.rb +1 -1
  18. data/lib/active_interaction.rb +25 -13
  19. data/spec/active_interaction/base_spec.rb +15 -39
  20. data/spec/active_interaction/concerns/active_recordable_spec.rb +51 -0
  21. data/spec/active_interaction/concerns/runnable_spec.rb +2 -34
  22. data/spec/active_interaction/errors_spec.rb +6 -89
  23. data/spec/active_interaction/filters/array_filter_spec.rb +2 -2
  24. data/spec/active_interaction/filters/file_filter_spec.rb +4 -4
  25. data/spec/active_interaction/filters/hash_filter_spec.rb +1 -17
  26. data/spec/active_interaction/filters/{model_filter_spec.rb → object_filter_spec.rb} +17 -17
  27. data/spec/active_interaction/i18n_spec.rb +1 -2
  28. data/spec/active_interaction/integration/array_interaction_spec.rb +10 -0
  29. data/spec/active_interaction/integration/hash_interaction_spec.rb +12 -2
  30. data/spec/active_interaction/integration/interface_interaction_spec.rb +10 -1
  31. data/spec/active_interaction/integration/object_interaction_spec.rb +16 -0
  32. data/spec/active_interaction/modules/validation_spec.rb +1 -2
  33. metadata +32 -29
  34. data/lib/active_interaction/concerns/transactable.rb +0 -79
  35. data/spec/active_interaction/concerns/transactable_spec.rb +0 -135
  36. data/spec/active_interaction/integration/model_interaction_spec.rb +0 -7
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_interaction
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Lasseigne
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-13 00:00:00.000000000 Z
12
+ date: 2015-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -37,112 +37,112 @@ dependencies:
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.6'
40
+ version: '1.9'
41
41
  type: :development
42
42
  prerelease: false
43
43
  version_requirements: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.6'
47
+ version: '1.9'
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: coveralls
50
50
  requirement: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.7'
54
+ version: '0.8'
55
55
  type: :development
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.7'
61
+ version: '0.8'
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: guard-rspec
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '4.2'
68
+ version: '4.5'
69
69
  type: :development
70
70
  prerelease: false
71
71
  version_requirements: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '4.2'
75
+ version: '4.5'
76
76
  - !ruby/object:Gem::Dependency
77
77
  name: guard-rubocop
78
78
  requirement: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.1'
82
+ version: '1.2'
83
83
  type: :development
84
84
  prerelease: false
85
85
  version_requirements: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.1'
89
+ version: '1.2'
90
90
  - !ruby/object:Gem::Dependency
91
91
  name: kramdown
92
92
  requirement: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.5'
96
+ version: '1.7'
97
97
  type: :development
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.5'
103
+ version: '1.7'
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: rake
106
106
  requirement: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '10.3'
110
+ version: '10.4'
111
111
  type: :development
112
112
  prerelease: false
113
113
  version_requirements: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '10.3'
117
+ version: '10.4'
118
118
  - !ruby/object:Gem::Dependency
119
119
  name: rspec
120
120
  requirement: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '3.1'
124
+ version: '3.2'
125
125
  type: :development
126
126
  prerelease: false
127
127
  version_requirements: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '3.1'
131
+ version: '3.2'
132
132
  - !ruby/object:Gem::Dependency
133
133
  name: rubocop
134
134
  requirement: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '0.28'
138
+ version: '0.30'
139
139
  type: :development
140
140
  prerelease: false
141
141
  version_requirements: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '0.28'
145
+ version: '0.30'
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: yard
148
148
  requirement: !ruby/object:Gem::Requirement
@@ -157,7 +157,9 @@ dependencies:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0.8'
160
- description: Manage application specific business logic.
160
+ description: |2
161
+ ActiveInteraction manages application-specific business logic. It is an
162
+ implementation of the command pattern in Ruby.
161
163
  email:
162
164
  - aaron.lasseigne@gmail.com
163
165
  - taylor@fausak.me
@@ -166,16 +168,17 @@ extensions: []
166
168
  extra_rdoc_files: []
167
169
  files:
168
170
  - CHANGELOG.md
171
+ - CONTRIBUTING.md
169
172
  - LICENSE.txt
170
173
  - README.md
171
174
  - lib/active_interaction.rb
172
175
  - lib/active_interaction/backports.rb
173
176
  - lib/active_interaction/base.rb
174
177
  - lib/active_interaction/concerns/active_modelable.rb
178
+ - lib/active_interaction/concerns/active_recordable.rb
175
179
  - lib/active_interaction/concerns/hashable.rb
176
180
  - lib/active_interaction/concerns/missable.rb
177
181
  - lib/active_interaction/concerns/runnable.rb
178
- - lib/active_interaction/concerns/transactable.rb
179
182
  - lib/active_interaction/errors.rb
180
183
  - lib/active_interaction/filter.rb
181
184
  - lib/active_interaction/filter_column.rb
@@ -192,7 +195,7 @@ files:
192
195
  - lib/active_interaction/filters/hash_filter.rb
193
196
  - lib/active_interaction/filters/integer_filter.rb
194
197
  - lib/active_interaction/filters/interface_filter.rb
195
- - lib/active_interaction/filters/model_filter.rb
198
+ - lib/active_interaction/filters/object_filter.rb
196
199
  - lib/active_interaction/filters/string_filter.rb
197
200
  - lib/active_interaction/filters/symbol_filter.rb
198
201
  - lib/active_interaction/filters/time_filter.rb
@@ -203,10 +206,10 @@ files:
203
206
  - lib/active_interaction/version.rb
204
207
  - spec/active_interaction/base_spec.rb
205
208
  - spec/active_interaction/concerns/active_modelable_spec.rb
209
+ - spec/active_interaction/concerns/active_recordable_spec.rb
206
210
  - spec/active_interaction/concerns/hashable_spec.rb
207
211
  - spec/active_interaction/concerns/missable_spec.rb
208
212
  - spec/active_interaction/concerns/runnable_spec.rb
209
- - spec/active_interaction/concerns/transactable_spec.rb
210
213
  - spec/active_interaction/errors_spec.rb
211
214
  - spec/active_interaction/filter_column_spec.rb
212
215
  - spec/active_interaction/filter_spec.rb
@@ -223,7 +226,7 @@ files:
223
226
  - spec/active_interaction/filters/hash_filter_spec.rb
224
227
  - spec/active_interaction/filters/integer_filter_spec.rb
225
228
  - spec/active_interaction/filters/interface_filter_spec.rb
226
- - spec/active_interaction/filters/model_filter_spec.rb
229
+ - spec/active_interaction/filters/object_filter_spec.rb
227
230
  - spec/active_interaction/filters/string_filter_spec.rb
228
231
  - spec/active_interaction/filters/symbol_filter_spec.rb
229
232
  - spec/active_interaction/filters/time_filter_spec.rb
@@ -238,7 +241,7 @@ files:
238
241
  - spec/active_interaction/integration/hash_interaction_spec.rb
239
242
  - spec/active_interaction/integration/integer_interaction_spec.rb
240
243
  - spec/active_interaction/integration/interface_interaction_spec.rb
241
- - spec/active_interaction/integration/model_interaction_spec.rb
244
+ - spec/active_interaction/integration/object_interaction_spec.rb
242
245
  - spec/active_interaction/integration/string_interaction_spec.rb
243
246
  - spec/active_interaction/integration/symbol_interaction_spec.rb
244
247
  - spec/active_interaction/integration/time_interaction_spec.rb
@@ -248,7 +251,7 @@ files:
248
251
  - spec/support/concerns.rb
249
252
  - spec/support/filters.rb
250
253
  - spec/support/interactions.rb
251
- homepage: http://orgsync.github.io/active_interaction/
254
+ homepage: http://devblog.orgsync.com/active_interaction/
252
255
  licenses:
253
256
  - MIT
254
257
  metadata: {}
@@ -268,17 +271,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
268
271
  version: '0'
269
272
  requirements: []
270
273
  rubyforge_project:
271
- rubygems_version: 2.2.2
274
+ rubygems_version: 2.4.6
272
275
  signing_key:
273
276
  specification_version: 4
274
277
  summary: Manage application specific business logic.
275
278
  test_files:
276
279
  - spec/active_interaction/base_spec.rb
277
280
  - spec/active_interaction/concerns/active_modelable_spec.rb
281
+ - spec/active_interaction/concerns/active_recordable_spec.rb
278
282
  - spec/active_interaction/concerns/hashable_spec.rb
279
283
  - spec/active_interaction/concerns/missable_spec.rb
280
284
  - spec/active_interaction/concerns/runnable_spec.rb
281
- - spec/active_interaction/concerns/transactable_spec.rb
282
285
  - spec/active_interaction/errors_spec.rb
283
286
  - spec/active_interaction/filter_column_spec.rb
284
287
  - spec/active_interaction/filter_spec.rb
@@ -295,7 +298,7 @@ test_files:
295
298
  - spec/active_interaction/filters/hash_filter_spec.rb
296
299
  - spec/active_interaction/filters/integer_filter_spec.rb
297
300
  - spec/active_interaction/filters/interface_filter_spec.rb
298
- - spec/active_interaction/filters/model_filter_spec.rb
301
+ - spec/active_interaction/filters/object_filter_spec.rb
299
302
  - spec/active_interaction/filters/string_filter_spec.rb
300
303
  - spec/active_interaction/filters/symbol_filter_spec.rb
301
304
  - spec/active_interaction/filters/time_filter_spec.rb
@@ -310,7 +313,7 @@ test_files:
310
313
  - spec/active_interaction/integration/hash_interaction_spec.rb
311
314
  - spec/active_interaction/integration/integer_interaction_spec.rb
312
315
  - spec/active_interaction/integration/interface_interaction_spec.rb
313
- - spec/active_interaction/integration/model_interaction_spec.rb
316
+ - spec/active_interaction/integration/object_interaction_spec.rb
314
317
  - spec/active_interaction/integration/string_interaction_spec.rb
315
318
  - spec/active_interaction/integration/symbol_interaction_spec.rb
316
319
  - spec/active_interaction/integration/time_interaction_spec.rb
@@ -1,79 +0,0 @@
1
- # coding: utf-8
2
-
3
- begin
4
- require 'active_record'
5
- rescue LoadError
6
- module ActiveRecord # rubocop:disable Documentation
7
- Rollback = Class.new(ActiveInteraction::Error)
8
-
9
- class Base # rubocop:disable Documentation
10
- def self.transaction(*)
11
- yield
12
- rescue Rollback
13
- end
14
- end
15
- end
16
- end
17
-
18
- module ActiveInteraction
19
- # @private
20
- #
21
- # Execute code in a transaction. If ActiveRecord isn't available, don't do
22
- # anything special.
23
- #
24
- # @since 1.2.0
25
- module Transactable
26
- extend ActiveSupport::Concern
27
-
28
- # @yield []
29
- def transaction
30
- return unless block_given?
31
-
32
- if self.class.transaction?
33
- ActiveRecord::Base.transaction(self.class.transaction_options) do
34
- yield
35
- end
36
- else
37
- yield
38
- end
39
- end
40
-
41
- module ClassMethods # rubocop:disable Documentation
42
- # @param klass [Class]
43
- def inherited(klass)
44
- klass.transaction(transaction?, transaction_options.dup)
45
-
46
- super
47
- end
48
-
49
- # @param enable [Boolean]
50
- # @param options [Hash]
51
- #
52
- # @return [nil]
53
- def transaction(enable, options = {})
54
- @_interaction_transaction_enabled = enable
55
- @_interaction_transaction_options = options
56
-
57
- nil
58
- end
59
-
60
- # @return [Boolean]
61
- def transaction?
62
- unless defined?(@_interaction_transaction_enabled)
63
- @_interaction_transaction_enabled = true
64
- end
65
-
66
- @_interaction_transaction_enabled
67
- end
68
-
69
- # @return [Hash]
70
- def transaction_options
71
- unless defined?(@_interaction_transaction_options)
72
- @_interaction_transaction_options = {}
73
- end
74
-
75
- @_interaction_transaction_options
76
- end
77
- end
78
- end
79
- end
@@ -1,135 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe ActiveRecord::Base do
6
- describe '.transaction' do
7
- it 'raises an error' do
8
- expect { described_class.transaction }.to raise_error LocalJumpError
9
- end
10
-
11
- it 'silently rescues ActiveRecord::Rollback' do
12
- expect do
13
- described_class.transaction do
14
- fail ActiveRecord::Rollback
15
- end
16
- end.to_not raise_error
17
- end
18
-
19
- context 'with a block' do
20
- it 'yields to the block' do
21
- expect { |b| described_class.transaction(&b) }.to yield_with_no_args
22
- end
23
-
24
- it 'accepts an argument' do
25
- expect { described_class.transaction(nil) {} }.to_not raise_error
26
- end
27
- end
28
- end
29
- end
30
-
31
- describe ActiveInteraction::Transactable do
32
- include_context 'concerns', ActiveInteraction::Transactable
33
-
34
- describe '.transaction' do
35
- it 'returns nil' do
36
- expect(klass.transaction(true)).to be_nil
37
- end
38
-
39
- it 'accepts a flag parameter' do
40
- expect { klass.transaction(true) }.to_not raise_error
41
- end
42
-
43
- it 'also accepts an options parameter' do
44
- expect { klass.transaction(true, {}) }.to_not raise_error
45
- end
46
- end
47
-
48
- describe '.transaction?' do
49
- it 'defaults to true' do
50
- expect(klass.transaction?).to be_truthy
51
- end
52
-
53
- it 'returns the stored value' do
54
- klass.transaction(false)
55
- expect(klass.transaction?).to be_falsey
56
- end
57
-
58
- context 'with a subclass' do
59
- before { klass.transaction(false) }
60
-
61
- let(:subclass) { Class.new(klass) }
62
-
63
- it 'inherits from the superclass' do
64
- expect(subclass.transaction?).to be_falsey
65
- end
66
- end
67
- end
68
-
69
- describe '.transaction_options' do
70
- let(:h) { { rand => rand } }
71
-
72
- it 'defaults to an empty hash' do
73
- expect(klass.transaction_options).to eql({})
74
- end
75
-
76
- it 'returns the stored value' do
77
- klass.transaction(klass.transaction?, h)
78
- expect(klass.transaction_options).to eql h
79
- end
80
-
81
- context 'with a subclass' do
82
- before { klass.transaction(klass.transaction?, h) }
83
-
84
- let(:subclass) { Class.new(klass) }
85
-
86
- it 'inherits from the superclass' do
87
- expect(subclass.transaction_options).to eql h
88
- end
89
- end
90
- end
91
-
92
- describe '#transaction' do
93
- let(:block) { -> { value } }
94
- let(:result) { instance.transaction(&block) }
95
- let(:value) { double }
96
-
97
- before do
98
- allow(ActiveRecord::Base).to receive(:transaction).and_call_original
99
- end
100
-
101
- it 'returns nil' do
102
- expect(instance.transaction).to be_nil
103
- end
104
-
105
- context 'with transactions disabled' do
106
- before do
107
- klass.transaction(false)
108
- end
109
-
110
- it 'returns the value of the block' do
111
- expect(result).to eql value
112
- end
113
-
114
- it 'does not call ActiveRecord::Base.transaction' do
115
- expect(ActiveRecord::Base).to_not have_received(:transaction)
116
- end
117
- end
118
-
119
- context 'with transactions enabled' do
120
- before do
121
- klass.transaction(true)
122
- end
123
-
124
- it 'returns the value of the block' do
125
- expect(result).to eql value
126
- end
127
-
128
- it 'calls ActiveRecord::Base.transaction' do
129
- result
130
- expect(ActiveRecord::Base).to have_received(:transaction)
131
- .once.with(klass.transaction_options, &block)
132
- end
133
- end
134
- end
135
- end
@@ -1,7 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe 'ModelInteraction' do
6
- it_behaves_like 'an interaction', :model, -> { // }, class: Regexp
7
- end