active_interaction 0.7.0 → 0.8.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +1 -1
- data/lib/active_interaction.rb +9 -6
- data/lib/active_interaction/base.rb +20 -22
- data/lib/active_interaction/filter.rb +14 -0
- data/lib/active_interaction/{active_model.rb → modules/active_model.rb} +0 -0
- data/lib/active_interaction/{core.rb → modules/core.rb} +26 -0
- data/lib/active_interaction/{method_missing.rb → modules/method_missing.rb} +0 -0
- data/lib/active_interaction/{overload_hash.rb → modules/overload_hash.rb} +0 -0
- data/lib/active_interaction/{validation.rb → modules/validation.rb} +0 -0
- data/lib/active_interaction/pipeline.rb +2 -1
- data/lib/active_interaction/version.rb +1 -1
- data/spec/active_interaction/{active_model_spec.rb → modules/active_model_spec.rb} +14 -17
- data/spec/active_interaction/{core_spec.rb → modules/core_spec.rb} +17 -5
- data/spec/active_interaction/{method_missing_spec.rb → modules/method_missing_spec.rb} +3 -8
- data/spec/active_interaction/{overload_hash_spec.rb → modules/overload_hash_spec.rb} +2 -1
- data/spec/active_interaction/{validation_spec.rb → modules/validation_spec.rb} +0 -0
- data/spec/support/filters.rb +18 -0
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f6687ab2fb463ecc05f0e785e9c05cf0b5d1172
|
4
|
+
data.tar.gz: d75174715db45471c960c5e1bb4effffb2ab9b7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 113199ae4863c2a7d78764179c9bd5caec7d516af78c921f1e788b5e9b1a2e251814b3e82786e790facc45d616f069e8a7b4e9e226a4d96b160e98e0c019e180
|
7
|
+
data.tar.gz: 5fefc55875416c15613c3edf28ca86d65996404ddb297037980360bab4f27a87bba7bad61b0eb6b9d51eaebce3fb337cee7234574b31a45d3b2356ec78514ef9
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# [Master][]
|
2
2
|
|
3
|
+
# [0.8.0][] (2013-11-14)
|
4
|
+
|
5
|
+
- Add ability to document interactions and filters.
|
6
|
+
|
3
7
|
# [0.7.0][] (2013-11-14)
|
4
8
|
|
5
9
|
- Add ability to chain a series of interactions together with
|
@@ -76,7 +80,8 @@
|
|
76
80
|
|
77
81
|
- Initial release.
|
78
82
|
|
79
|
-
[master]: https://github.com/orgsync/active_interaction/compare/v0.
|
83
|
+
[master]: https://github.com/orgsync/active_interaction/compare/v0.8.0...master
|
84
|
+
[0.8.0]: https://github.com/orgsync/active_interaction/compare/v0.7.0...v0.8.0
|
80
85
|
[0.7.0]: https://github.com/orgsync/active_interaction/compare/v0.6.1...v0.7.0
|
81
86
|
[0.6.1]: https://github.com/orgsync/active_interaction/compare/v0.6.0...v0.6.1
|
82
87
|
[0.6.0]: https://github.com/orgsync/active_interaction/compare/v0.5.0...v0.6.0
|
data/README.md
CHANGED
data/lib/active_interaction.rb
CHANGED
@@ -2,10 +2,15 @@ require 'active_model'
|
|
2
2
|
|
3
3
|
require 'active_interaction/version'
|
4
4
|
require 'active_interaction/errors'
|
5
|
-
|
6
|
-
require 'active_interaction/
|
7
|
-
require 'active_interaction/
|
5
|
+
|
6
|
+
require 'active_interaction/modules/active_model'
|
7
|
+
require 'active_interaction/modules/core'
|
8
|
+
require 'active_interaction/modules/method_missing'
|
9
|
+
require 'active_interaction/modules/overload_hash'
|
10
|
+
require 'active_interaction/modules/validation'
|
11
|
+
|
8
12
|
require 'active_interaction/filter'
|
13
|
+
require 'active_interaction/filters'
|
9
14
|
require 'active_interaction/filters/abstract_date_time_filter'
|
10
15
|
require 'active_interaction/filters/abstract_numeric_filter'
|
11
16
|
require 'active_interaction/filters/array_filter'
|
@@ -20,9 +25,7 @@ require 'active_interaction/filters/model_filter'
|
|
20
25
|
require 'active_interaction/filters/string_filter'
|
21
26
|
require 'active_interaction/filters/symbol_filter'
|
22
27
|
require 'active_interaction/filters/time_filter'
|
23
|
-
|
24
|
-
require 'active_interaction/validation'
|
25
|
-
require 'active_interaction/core'
|
28
|
+
|
26
29
|
require 'active_interaction/base'
|
27
30
|
require 'active_interaction/pipeline'
|
28
31
|
|
@@ -33,25 +33,15 @@ module ActiveInteraction
|
|
33
33
|
|
34
34
|
validate :input_errors, :runtime_errors
|
35
35
|
|
36
|
-
# Returns the inputs provided to {.run} or {.run!} after being cast based
|
37
|
-
# on the filters in the class.
|
38
|
-
#
|
39
|
-
# @return [Hash{Symbol => Object}] All inputs passed to {.run} or {.run!}.
|
40
|
-
#
|
41
|
-
# @since 0.6.0
|
42
|
-
def inputs
|
43
|
-
self.class.filters.reduce({}) do |h, filter|
|
44
|
-
h[filter.name] = send(filter.name)
|
45
|
-
h
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
36
|
# @param options [Hash{Symbol => Object}] Attribute values to set.
|
50
37
|
#
|
51
38
|
# @private
|
52
39
|
def initialize(options = {})
|
53
|
-
|
40
|
+
@_interaction_errors = Errors.new(self)
|
41
|
+
@_interaction_result = nil
|
42
|
+
@_interaction_runtime_errors = nil
|
54
43
|
|
44
|
+
options = options.symbolize_keys
|
55
45
|
options.each do |key, value|
|
56
46
|
if key.to_s.start_with?('_interaction_')
|
57
47
|
raise InvalidValueError, key.inspect
|
@@ -68,6 +58,19 @@ module ActiveInteraction
|
|
68
58
|
end
|
69
59
|
end
|
70
60
|
|
61
|
+
# Returns the inputs provided to {.run} or {.run!} after being cast based
|
62
|
+
# on the filters in the class.
|
63
|
+
#
|
64
|
+
# @return [Hash{Symbol => Object}] All inputs passed to {.run} or {.run!}.
|
65
|
+
#
|
66
|
+
# @since 0.6.0
|
67
|
+
def inputs
|
68
|
+
self.class.filters.reduce({}) do |h, filter|
|
69
|
+
h[filter.name] = send(filter.name)
|
70
|
+
h
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
71
74
|
# Runs the business logic associated with the interaction. The method is
|
72
75
|
# only run when there are no validation errors. The return value is
|
73
76
|
# placed into {#result}. This method must be overridden in the subclass.
|
@@ -86,17 +89,12 @@ module ActiveInteraction
|
|
86
89
|
# @return [Nil] if there are validation errors.
|
87
90
|
# @return [Object] if there are no validation errors.
|
88
91
|
def result
|
89
|
-
|
90
|
-
if instance_variable_defined?(symbol)
|
91
|
-
instance_variable_get(symbol)
|
92
|
-
else
|
93
|
-
nil
|
94
|
-
end
|
92
|
+
@_interaction_result
|
95
93
|
end
|
96
94
|
|
97
95
|
# @private
|
98
96
|
def errors
|
99
|
-
@_interaction_errors
|
97
|
+
@_interaction_errors
|
100
98
|
end
|
101
99
|
|
102
100
|
# @private
|
@@ -164,7 +162,7 @@ module ActiveInteraction
|
|
164
162
|
end
|
165
163
|
|
166
164
|
def runtime_errors
|
167
|
-
return unless
|
165
|
+
return unless @_interaction_runtime_errors
|
168
166
|
|
169
167
|
@_interaction_runtime_errors.symbolic.each do |attribute, symbols|
|
170
168
|
symbols.each { |symbol| errors.add_sym(attribute, symbol) }
|
@@ -6,6 +6,7 @@ module ActiveInteraction
|
|
6
6
|
# @param options [Hash{Symbol => Object}]
|
7
7
|
#
|
8
8
|
# @option options [Object] :default fallback value if `nil` is given
|
9
|
+
# @option options [String] :desc human-readable description of this input
|
9
10
|
|
10
11
|
# Describes an input filter for an interaction.
|
11
12
|
#
|
@@ -164,6 +165,19 @@ module ActiveInteraction
|
|
164
165
|
raise InvalidDefaultError, "#{name}: #{options[:default].inspect}"
|
165
166
|
end
|
166
167
|
|
168
|
+
# Get the description.
|
169
|
+
#
|
170
|
+
# @example
|
171
|
+
# ActiveInteraction::Filter.new(:example, desc: 'description').desc
|
172
|
+
# # => "description"
|
173
|
+
#
|
174
|
+
# @return [String, nil] the description
|
175
|
+
#
|
176
|
+
# @since 0.8.0
|
177
|
+
def desc
|
178
|
+
options[:desc]
|
179
|
+
end
|
180
|
+
|
167
181
|
# Tells if this filter has a default value.
|
168
182
|
#
|
169
183
|
# @example
|
File without changes
|
@@ -9,6 +9,32 @@ module ActiveInteraction
|
|
9
9
|
# @see Base
|
10
10
|
# @see Pipeline
|
11
11
|
module Core
|
12
|
+
# Get or set the description.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# core.desc
|
16
|
+
# # => nil
|
17
|
+
# core.desc('descriptive!')
|
18
|
+
# core.desc
|
19
|
+
# # => "descriptive!"
|
20
|
+
#
|
21
|
+
# @param desc [String, nil] what to set the description to
|
22
|
+
#
|
23
|
+
# @return [String, nil] the description
|
24
|
+
#
|
25
|
+
# @since 0.8.0
|
26
|
+
def desc(desc = nil)
|
27
|
+
if desc.nil?
|
28
|
+
unless instance_variable_defined?(:@_interaction_desc)
|
29
|
+
@_interaction_desc = nil
|
30
|
+
end
|
31
|
+
else
|
32
|
+
@_interaction_desc = desc
|
33
|
+
end
|
34
|
+
|
35
|
+
@_interaction_desc
|
36
|
+
end
|
37
|
+
|
12
38
|
# Like {Base.run} except that it returns the value of {Base#execute} or
|
13
39
|
# raises an exception if there were any validation errors.
|
14
40
|
#
|
File without changes
|
File without changes
|
File without changes
|
@@ -60,10 +60,11 @@ module ActiveInteraction
|
|
60
60
|
# @raise [EmptyPipelineError] if nothing is in the pipeline
|
61
61
|
def run(*args)
|
62
62
|
raise EmptyPipelineError if @steps.empty?
|
63
|
+
|
63
64
|
transaction do
|
64
65
|
function, interaction = @steps.first
|
65
66
|
outcome = interaction.run(function.call(*args))
|
66
|
-
@steps
|
67
|
+
@steps.drop(1).reduce(outcome) { |o, (f, i)| bind(o, f, i) }
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
@@ -1,33 +1,30 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveInteraction::ActiveModel do
|
4
|
-
|
5
|
-
|
6
|
-
include ActiveInteraction::ActiveModel
|
7
|
-
end
|
8
|
-
end
|
4
|
+
let(:klass) { Class.new { include ActiveInteraction::ActiveModel } }
|
5
|
+
subject(:instance) { klass.new }
|
9
6
|
|
10
|
-
describe '
|
11
|
-
it 'returns
|
12
|
-
expect(
|
7
|
+
describe '.i18n_scope' do
|
8
|
+
it 'returns the scope' do
|
9
|
+
expect(klass.i18n_scope).to eq :active_interaction
|
13
10
|
end
|
14
11
|
end
|
15
12
|
|
16
|
-
describe '#
|
17
|
-
it 'returns
|
18
|
-
expect(
|
13
|
+
describe '#i18n_scope' do
|
14
|
+
it 'returns the scope' do
|
15
|
+
expect(instance.i18n_scope).to eq :active_interaction
|
19
16
|
end
|
20
17
|
end
|
21
18
|
|
22
|
-
describe '
|
23
|
-
it 'returns
|
24
|
-
expect(
|
19
|
+
describe '#new_record?' do
|
20
|
+
it 'returns true' do
|
21
|
+
expect(instance).to be_new_record
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
28
|
-
describe '#
|
29
|
-
it 'returns
|
30
|
-
expect(
|
25
|
+
describe '#persisted?' do
|
26
|
+
it 'returns false' do
|
27
|
+
expect(instance).to_not be_persisted
|
31
28
|
end
|
32
29
|
end
|
33
30
|
end
|
@@ -1,13 +1,25 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveInteraction::Core do
|
4
|
-
let(:
|
5
|
-
|
6
|
-
|
4
|
+
let(:klass) { Class.new { include ActiveInteraction::Core } }
|
5
|
+
subject(:instance) { klass.new }
|
6
|
+
|
7
|
+
describe '#desc' do
|
8
|
+
let(:desc) { SecureRandom.hex }
|
9
|
+
|
10
|
+
it 'returns nil' do
|
11
|
+
expect(instance.desc).to be_nil
|
7
12
|
end
|
8
|
-
end
|
9
13
|
|
10
|
-
|
14
|
+
it 'returns the description' do
|
15
|
+
expect(instance.desc(desc)).to eq desc
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'saves the description' do
|
19
|
+
instance.desc(desc)
|
20
|
+
expect(instance.desc).to eq desc
|
21
|
+
end
|
22
|
+
end
|
11
23
|
|
12
24
|
describe '#run!' do
|
13
25
|
let(:errors) { double(full_messages: []) }
|
@@ -1,13 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveInteraction::MethodMissing do
|
4
|
-
let(:
|
5
|
-
|
6
|
-
include ActiveInteraction::MethodMissing
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
subject(:instance) { model.new }
|
4
|
+
let(:klass) { Class.new { include ActiveInteraction::MethodMissing } }
|
5
|
+
subject(:instance) { klass.new }
|
11
6
|
|
12
7
|
describe '#method_missing' do
|
13
8
|
context 'with invalid slug' do
|
@@ -16,7 +11,7 @@ describe ActiveInteraction::MethodMissing do
|
|
16
11
|
it 'calls super' do
|
17
12
|
expect {
|
18
13
|
instance.method_missing(slug)
|
19
|
-
}.to raise_error
|
14
|
+
}.to raise_error NameError
|
20
15
|
end
|
21
16
|
end
|
22
17
|
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveInteraction::OverloadHash do
|
4
|
-
|
4
|
+
let(:klass) { Class.new { include ActiveInteraction::OverloadHash } }
|
5
|
+
subject(:instance) { klass.new }
|
5
6
|
|
6
7
|
describe '#hash(*args, &block)' do
|
7
8
|
context 'with no arguments' do
|
File without changes
|
data/spec/support/filters.rb
CHANGED
@@ -153,6 +153,24 @@ shared_examples_for 'a filter' do
|
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
|
+
describe '#desc' do
|
157
|
+
it 'returns nil' do
|
158
|
+
expect(filter.desc).to be_nil
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'with a description' do
|
162
|
+
let(:desc) { SecureRandom.hex }
|
163
|
+
|
164
|
+
before do
|
165
|
+
options.merge!(desc: desc)
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'returns the description' do
|
169
|
+
expect(filter.desc).to eq desc
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
156
174
|
describe '#filters' do
|
157
175
|
it 'returns Filters' do
|
158
176
|
expect(filter.filters).to be_an ActiveInteraction::Filters
|
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: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Lasseigne
|
@@ -151,9 +151,7 @@ executables: []
|
|
151
151
|
extensions: []
|
152
152
|
extra_rdoc_files: []
|
153
153
|
files:
|
154
|
-
- lib/active_interaction/active_model.rb
|
155
154
|
- lib/active_interaction/base.rb
|
156
|
-
- lib/active_interaction/core.rb
|
157
155
|
- lib/active_interaction/errors.rb
|
158
156
|
- lib/active_interaction/filter.rb
|
159
157
|
- lib/active_interaction/filters/abstract_date_time_filter.rb
|
@@ -171,15 +169,15 @@ files:
|
|
171
169
|
- lib/active_interaction/filters/symbol_filter.rb
|
172
170
|
- lib/active_interaction/filters/time_filter.rb
|
173
171
|
- lib/active_interaction/filters.rb
|
174
|
-
- lib/active_interaction/
|
175
|
-
- lib/active_interaction/
|
172
|
+
- lib/active_interaction/modules/active_model.rb
|
173
|
+
- lib/active_interaction/modules/core.rb
|
174
|
+
- lib/active_interaction/modules/method_missing.rb
|
175
|
+
- lib/active_interaction/modules/overload_hash.rb
|
176
|
+
- lib/active_interaction/modules/validation.rb
|
176
177
|
- lib/active_interaction/pipeline.rb
|
177
|
-
- lib/active_interaction/validation.rb
|
178
178
|
- lib/active_interaction/version.rb
|
179
179
|
- lib/active_interaction.rb
|
180
|
-
- spec/active_interaction/active_model_spec.rb
|
181
180
|
- spec/active_interaction/base_spec.rb
|
182
|
-
- spec/active_interaction/core_spec.rb
|
183
181
|
- spec/active_interaction/errors_spec.rb
|
184
182
|
- spec/active_interaction/filter_spec.rb
|
185
183
|
- spec/active_interaction/filters/array_filter_spec.rb
|
@@ -208,10 +206,12 @@ files:
|
|
208
206
|
- spec/active_interaction/integration/string_interaction_spec.rb
|
209
207
|
- spec/active_interaction/integration/symbol_interaction_spec.rb
|
210
208
|
- spec/active_interaction/integration/time_interaction_spec.rb
|
211
|
-
- spec/active_interaction/
|
212
|
-
- spec/active_interaction/
|
209
|
+
- spec/active_interaction/modules/active_model_spec.rb
|
210
|
+
- spec/active_interaction/modules/core_spec.rb
|
211
|
+
- spec/active_interaction/modules/method_missing_spec.rb
|
212
|
+
- spec/active_interaction/modules/overload_hash_spec.rb
|
213
|
+
- spec/active_interaction/modules/validation_spec.rb
|
213
214
|
- spec/active_interaction/pipeline_spec.rb
|
214
|
-
- spec/active_interaction/validation_spec.rb
|
215
215
|
- spec/spec_helper.rb
|
216
216
|
- spec/support/filters.rb
|
217
217
|
- spec/support/interactions.rb
|
@@ -243,9 +243,7 @@ signing_key:
|
|
243
243
|
specification_version: 4
|
244
244
|
summary: Manage application specific business logic.
|
245
245
|
test_files:
|
246
|
-
- spec/active_interaction/active_model_spec.rb
|
247
246
|
- spec/active_interaction/base_spec.rb
|
248
|
-
- spec/active_interaction/core_spec.rb
|
249
247
|
- spec/active_interaction/errors_spec.rb
|
250
248
|
- spec/active_interaction/filter_spec.rb
|
251
249
|
- spec/active_interaction/filters/array_filter_spec.rb
|
@@ -274,10 +272,12 @@ test_files:
|
|
274
272
|
- spec/active_interaction/integration/string_interaction_spec.rb
|
275
273
|
- spec/active_interaction/integration/symbol_interaction_spec.rb
|
276
274
|
- spec/active_interaction/integration/time_interaction_spec.rb
|
277
|
-
- spec/active_interaction/
|
278
|
-
- spec/active_interaction/
|
275
|
+
- spec/active_interaction/modules/active_model_spec.rb
|
276
|
+
- spec/active_interaction/modules/core_spec.rb
|
277
|
+
- spec/active_interaction/modules/method_missing_spec.rb
|
278
|
+
- spec/active_interaction/modules/overload_hash_spec.rb
|
279
|
+
- spec/active_interaction/modules/validation_spec.rb
|
279
280
|
- spec/active_interaction/pipeline_spec.rb
|
280
|
-
- spec/active_interaction/validation_spec.rb
|
281
281
|
- spec/spec_helper.rb
|
282
282
|
- spec/support/filters.rb
|
283
283
|
- spec/support/interactions.rb
|