active_interaction 1.4.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -2
- data/README.md +44 -32
- data/lib/active_interaction.rb +2 -1
- data/lib/active_interaction/base.rb +1 -25
- data/lib/active_interaction/concerns/active_recordable.rb +58 -0
- data/lib/active_interaction/version.rb +1 -1
- data/spec/active_interaction/base_spec.rb +0 -25
- data/spec/active_interaction/concerns/active_recordable_spec.rb +51 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ba87c0f7766f1154697c93d29d10c0b0b0774d0
|
4
|
+
data.tar.gz: 0d299041f295fe030c7353fa23d058ac1d3f0f27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02ce12f0701b9ec571b9988f0ba2bbdee87611b8504542ea052fa02fc854079c2ded5962b782e066b43d17812aee70d89750ed4c8a2d84204c05285e6de03b7e
|
7
|
+
data.tar.gz: eef2e988d3daa2e5ff0ea85a94fdfd9a4d4fc4acebb1b7ec555c326c2b8d6d4c4643038cb5955102d8427ef6200cca930d8cd13c78dda6e02c456cf9d03e91ae
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
-
# [
|
1
|
+
# [1.5.0][] (2015-02-05)
|
2
|
+
|
3
|
+
## Added
|
4
|
+
|
5
|
+
- [#248][]: Add `has_attribute?` support to an instance of an interaction.
|
6
|
+
|
7
|
+
## Fixed
|
8
|
+
|
9
|
+
- [#248][]: Fix support for simple_form gem.
|
2
10
|
|
3
11
|
# [1.4.1][] (2014-12-12)
|
4
12
|
|
@@ -366,7 +374,7 @@
|
|
366
374
|
|
367
375
|
- Initial release.
|
368
376
|
|
369
|
-
[
|
377
|
+
[1.5.0]: https://github.com/orgsync/active_interaction/compare/v1.4.1...1.5.0
|
370
378
|
[1.4.1]: https://github.com/orgsync/active_interaction/compare/v1.4.0...v1.4.1
|
371
379
|
[1.4.0]: https://github.com/orgsync/active_interaction/compare/v1.3.1...v1.4.0
|
372
380
|
[1.3.1]: https://github.com/orgsync/active_interaction/compare/v1.3.0...v1.3.1
|
@@ -482,3 +490,4 @@
|
|
482
490
|
[#235]: https://github.com/orgsync/active_interaction/issues/235
|
483
491
|
[#239]: https://github.com/orgsync/active_interaction/issues/239
|
484
492
|
[#244]: https://github.com/orgsync/active_interaction/issues/244
|
493
|
+
[#248]: https://github.com/orgsync/active_interaction/issues/248
|
data/README.md
CHANGED
@@ -1,10 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
<p align="center">
|
2
|
+
<img alt="briefcase" src="briefcase.png">
|
3
|
+
</p>
|
4
|
+
|
5
|
+
<h1 align="center">ActiveInteraction</h1>
|
6
|
+
|
7
|
+
<p align="center">Manage application specific business logic.</p>
|
8
|
+
|
9
|
+
<p align="center">
|
10
|
+
<a href="https://rubygems.org/gems/active_interaction">
|
11
|
+
<img alt="Gem Version" src="https://img.shields.io/gem/v/active_interaction.svg?style=flat">
|
12
|
+
</a>
|
13
|
+
<a href="https://travis-ci.org/orgsync/active_interaction">
|
14
|
+
<img alt="Build Status" src="https://img.shields.io/travis/orgsync/active_interaction/master.svg?style=flat">
|
15
|
+
</a>
|
16
|
+
<a href="https://coveralls.io/r/orgsync/active_interaction?branch=master">
|
17
|
+
<img alt="Coverage Status" src="https://img.shields.io/coveralls/orgsync/active_interaction/master.svg?style=flat">
|
18
|
+
</a>
|
19
|
+
<a href="https://codeclimate.com/github/orgsync/active_interaction">
|
20
|
+
<img alt="Code Climate" src="https://img.shields.io/codeclimate/github/orgsync/active_interaction.svg?style=flat">
|
21
|
+
</a>
|
22
|
+
<a href="https://gemnasium.com/orgsync/active_interaction">
|
23
|
+
<img alt="Dependency Status" src="https://img.shields.io/gemnasium/orgsync/active_interaction.svg?style=flat">
|
24
|
+
</a>
|
25
|
+
|
26
|
+
<hr>
|
27
|
+
</p>
|
8
28
|
|
9
29
|
At first it seemed alright. A little business logic in a controller
|
10
30
|
or model wasn't going to hurt anything. Then one day you wake up
|
@@ -15,17 +35,17 @@ to this.
|
|
15
35
|
Take back control. Slim down models and wrangle monstrous controller
|
16
36
|
methods with ActiveInteraction.
|
17
37
|
|
18
|
-
Read more on the [project page][
|
38
|
+
Read more on the [project page][1] or check out the full [documentation][2]
|
19
39
|
on RubyDoc.info.
|
20
40
|
|
21
41
|
## Installation
|
22
42
|
|
23
|
-
This project uses [semantic versioning][
|
43
|
+
This project uses [semantic versioning][3].
|
24
44
|
|
25
45
|
Add it to your Gemfile:
|
26
46
|
|
27
47
|
``` ruby
|
28
|
-
gem 'active_interaction', '~> 1.
|
48
|
+
gem 'active_interaction', '~> 1.5'
|
29
49
|
```
|
30
50
|
|
31
51
|
And then execute:
|
@@ -276,25 +296,17 @@ p Interaction.run.errors.messages
|
|
276
296
|
|
277
297
|
## Credits
|
278
298
|
|
279
|
-
ActiveInteraction is brought to you by [@AaronLasseigne][
|
280
|
-
[@tfausak][
|
281
|
-
work done in [Mutations][
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
[
|
286
|
-
[
|
287
|
-
[
|
288
|
-
[
|
289
|
-
[
|
290
|
-
[
|
291
|
-
[
|
292
|
-
[
|
293
|
-
[10]: https://gemnasium.com/orgsync/active_interaction "Dependency Status"
|
294
|
-
[11]: http://orgsync.github.io/active_interaction/
|
295
|
-
[12]: http://rubydoc.info/github/orgsync/active_interaction
|
296
|
-
[13]: http://semver.org/spec/v2.0.0.html
|
297
|
-
[14]: https://github.com/AaronLasseigne
|
298
|
-
[15]: https://github.com/tfausak
|
299
|
-
[16]: https://github.com/orgsync
|
300
|
-
[17]: https://github.com/cypriss/mutations
|
299
|
+
ActiveInteraction is brought to you by [@AaronLasseigne][4] and
|
300
|
+
[@tfausak][5] from [@orgsync][6]. We were inspired by the fantastic
|
301
|
+
work done in [Mutations][7].
|
302
|
+
|
303
|
+
Logo provided free by [Emoji One][8].
|
304
|
+
|
305
|
+
[1]: http://orgsync.github.io/active_interaction/
|
306
|
+
[2]: http://rubydoc.info/github/orgsync/active_interaction
|
307
|
+
[3]: http://semver.org/spec/v2.0.0.html
|
308
|
+
[4]: https://github.com/AaronLasseigne
|
309
|
+
[5]: https://github.com/tfausak
|
310
|
+
[6]: https://github.com/orgsync
|
311
|
+
[7]: https://github.com/cypriss/mutations
|
312
|
+
[8]: http://emojione.com/
|
data/lib/active_interaction.rb
CHANGED
@@ -6,6 +6,7 @@ require 'active_interaction/version'
|
|
6
6
|
require 'active_interaction/errors'
|
7
7
|
|
8
8
|
require 'active_interaction/concerns/active_modelable'
|
9
|
+
require 'active_interaction/concerns/active_recordable'
|
9
10
|
require 'active_interaction/concerns/hashable'
|
10
11
|
require 'active_interaction/concerns/missable'
|
11
12
|
require 'active_interaction/concerns/transactable'
|
@@ -50,5 +51,5 @@ I18n.load_path.unshift(*Dir[File.expand_path(
|
|
50
51
|
#
|
51
52
|
# @since 1.0.0
|
52
53
|
#
|
53
|
-
# @version 1.
|
54
|
+
# @version 1.5.0
|
54
55
|
module ActiveInteraction end
|
@@ -29,6 +29,7 @@ module ActiveInteraction
|
|
29
29
|
# end
|
30
30
|
class Base
|
31
31
|
include ActiveModelable
|
32
|
+
include ActiveRecordable
|
32
33
|
include Runnable
|
33
34
|
|
34
35
|
define_callbacks :type_check
|
@@ -181,31 +182,6 @@ module ActiveInteraction
|
|
181
182
|
process_inputs(inputs.symbolize_keys)
|
182
183
|
end
|
183
184
|
|
184
|
-
# Returns the column object for the named filter.
|
185
|
-
#
|
186
|
-
# @param name [Symbol] The name of a filter.
|
187
|
-
#
|
188
|
-
# @example
|
189
|
-
# class Interaction < ActiveInteraction::Base
|
190
|
-
# string :email, default: nil
|
191
|
-
#
|
192
|
-
# def execute; end
|
193
|
-
# end
|
194
|
-
#
|
195
|
-
# Interaction.new.column_for_attribute(:email)
|
196
|
-
# # => #<ActiveInteraction::FilterColumn:0x007faebeb2a6c8 @type=:string>
|
197
|
-
#
|
198
|
-
# Interaction.new.column_for_attribute(:not_a_filter)
|
199
|
-
# # => nil
|
200
|
-
#
|
201
|
-
# @return [FilterColumn, nil]
|
202
|
-
#
|
203
|
-
# @since 1.2.0
|
204
|
-
def column_for_attribute(name)
|
205
|
-
filter = self.class.filters[name]
|
206
|
-
FilterColumn.intern(filter.database_column_type) if filter
|
207
|
-
end
|
208
|
-
|
209
185
|
# @!method compose(other, inputs = {})
|
210
186
|
# Run another interaction and return its result. If the other interaction
|
211
187
|
# fails, halt execution.
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module ActiveInteraction
|
4
|
+
# Implement the minimal ActiveRecord interface.
|
5
|
+
#
|
6
|
+
# @private
|
7
|
+
module ActiveRecordable
|
8
|
+
# Returns the column object for the named filter.
|
9
|
+
#
|
10
|
+
# @param name [Symbol] The name of a filter.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# class Interaction < ActiveInteraction::Base
|
14
|
+
# string :email, default: nil
|
15
|
+
#
|
16
|
+
# def execute; end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# Interaction.new.column_for_attribute(:email)
|
20
|
+
# # => #<ActiveInteraction::FilterColumn:0x007faebeb2a6c8 @type=:string>
|
21
|
+
#
|
22
|
+
# Interaction.new.column_for_attribute(:not_a_filter)
|
23
|
+
# # => nil
|
24
|
+
#
|
25
|
+
# @return [FilterColumn, nil]
|
26
|
+
#
|
27
|
+
# @since 1.2.0
|
28
|
+
def column_for_attribute(name)
|
29
|
+
filter = self.class.filters[name]
|
30
|
+
FilterColumn.intern(filter.database_column_type) if filter
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns true if a filter of that name exists.
|
34
|
+
#
|
35
|
+
# @param name [String, Symbol] The name of a filter.
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# class Interaction < ActiveInteraction::Base
|
39
|
+
# string :email, default: nil
|
40
|
+
#
|
41
|
+
# def execute; end
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# Interaction.new.has_attribute?(:email)
|
45
|
+
# # => true
|
46
|
+
#
|
47
|
+
# Interaction.new.has_attribute?(:not_a_filter)
|
48
|
+
# # => false
|
49
|
+
#
|
50
|
+
# @return [Boolean]
|
51
|
+
#
|
52
|
+
# @since 1.5.0
|
53
|
+
def has_attribute?(name) # rubocop:disable PredicateName
|
54
|
+
self.class.filters.key?(name.to_sym)
|
55
|
+
end
|
56
|
+
# rubocop:enable PredicateName
|
57
|
+
end
|
58
|
+
end
|
@@ -313,31 +313,6 @@ describe ActiveInteraction::Base do
|
|
313
313
|
end
|
314
314
|
end
|
315
315
|
|
316
|
-
describe '#column_for_attribute(name)' do
|
317
|
-
let(:described_class) { InteractionWithFilter }
|
318
|
-
let(:column) { outcome.column_for_attribute(name) }
|
319
|
-
|
320
|
-
context 'name is not an input name' do
|
321
|
-
let(:name) { SecureRandom.hex }
|
322
|
-
|
323
|
-
it 'returns nil if the attribute cannot be found' do
|
324
|
-
expect(column).to be_nil
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
context 'name is an input name' do
|
329
|
-
let(:name) { InteractionWithFilter.filters.keys.first }
|
330
|
-
|
331
|
-
it 'returns a FilterColumn' do
|
332
|
-
expect(column).to be_a ActiveInteraction::FilterColumn
|
333
|
-
end
|
334
|
-
|
335
|
-
it 'returns a FilterColumn of type boolean' do
|
336
|
-
expect(column.type).to eql :float
|
337
|
-
end
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
316
|
describe '#inputs' do
|
342
317
|
let(:described_class) { InteractionWithFilter }
|
343
318
|
let(:other_val) { SecureRandom.hex }
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
InteractionWithFilter = Class.new(TestInteraction) do
|
6
|
+
float :thing
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ActiveInteraction::ActiveRecordable do
|
10
|
+
include_context 'interactions'
|
11
|
+
|
12
|
+
let(:described_class) { InteractionWithFilter }
|
13
|
+
|
14
|
+
describe '#column_for_attribute(name)' do
|
15
|
+
let(:column) { outcome.column_for_attribute(name) }
|
16
|
+
|
17
|
+
context 'name is not an input name' do
|
18
|
+
let(:name) { SecureRandom.hex }
|
19
|
+
|
20
|
+
it 'returns nil if the attribute cannot be found' do
|
21
|
+
expect(column).to be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'name is an input name' do
|
26
|
+
let(:name) { described_class.filters.keys.first }
|
27
|
+
|
28
|
+
it 'returns a FilterColumn' do
|
29
|
+
expect(column).to be_a ActiveInteraction::FilterColumn
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns a FilterColumn of type boolean' do
|
33
|
+
expect(column.type).to eql :float
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#has_attribute?' do
|
39
|
+
it 'returns true if the filter exists' do
|
40
|
+
expect(outcome.has_attribute?(:thing)).to be_truthy
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'works with strings' do
|
44
|
+
expect(outcome.has_attribute?('thing')).to be_truthy
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'returns false if the filter does not exist' do
|
48
|
+
expect(outcome.has_attribute?(:not_a_filter)).to be_falsey
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
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
|
+
version: 1.5.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:
|
12
|
+
date: 2015-02-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -172,6 +172,7 @@ files:
|
|
172
172
|
- lib/active_interaction/backports.rb
|
173
173
|
- lib/active_interaction/base.rb
|
174
174
|
- lib/active_interaction/concerns/active_modelable.rb
|
175
|
+
- lib/active_interaction/concerns/active_recordable.rb
|
175
176
|
- lib/active_interaction/concerns/hashable.rb
|
176
177
|
- lib/active_interaction/concerns/missable.rb
|
177
178
|
- lib/active_interaction/concerns/runnable.rb
|
@@ -203,6 +204,7 @@ files:
|
|
203
204
|
- lib/active_interaction/version.rb
|
204
205
|
- spec/active_interaction/base_spec.rb
|
205
206
|
- spec/active_interaction/concerns/active_modelable_spec.rb
|
207
|
+
- spec/active_interaction/concerns/active_recordable_spec.rb
|
206
208
|
- spec/active_interaction/concerns/hashable_spec.rb
|
207
209
|
- spec/active_interaction/concerns/missable_spec.rb
|
208
210
|
- spec/active_interaction/concerns/runnable_spec.rb
|
@@ -268,13 +270,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
268
270
|
version: '0'
|
269
271
|
requirements: []
|
270
272
|
rubyforge_project:
|
271
|
-
rubygems_version: 2.
|
273
|
+
rubygems_version: 2.4.5
|
272
274
|
signing_key:
|
273
275
|
specification_version: 4
|
274
276
|
summary: Manage application specific business logic.
|
275
277
|
test_files:
|
276
278
|
- spec/active_interaction/base_spec.rb
|
277
279
|
- spec/active_interaction/concerns/active_modelable_spec.rb
|
280
|
+
- spec/active_interaction/concerns/active_recordable_spec.rb
|
278
281
|
- spec/active_interaction/concerns/hashable_spec.rb
|
279
282
|
- spec/active_interaction/concerns/missable_spec.rb
|
280
283
|
- spec/active_interaction/concerns/runnable_spec.rb
|