simple_interaction 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/simple_interaction.rb +7 -8
- data/lib/simple_interaction/class_methods.rb +3 -4
- data/lib/simple_interaction/exceptions.rb +0 -2
- data/lib/simple_interaction/instance_methods.rb +11 -3
- data/lib/simple_interaction/version.rb +1 -1
- data/test/interaction_test.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25093061e94aa86fd29acc1215bd80f85198d066
|
4
|
+
data.tar.gz: 3e28619e02a9d42a5f32b57b3a93c37d0133eb49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04a64cdb4430e965be669b6b2ef8173c9ba2e08db1966df45c7ab64dcd1a63a9e3a75a28659f63f9670addc38f0e36d29f27f1f43ffdc31843edb24799790c1c
|
7
|
+
data.tar.gz: b85a547308bb033c7546d1cb7ff4316aaf0147221695438ea5b3c91aca53b8a31dbec383fb189f1f6c8872e8711fc0f33475bd6645e348272d64d7964216a24a
|
data/README.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
[![Code Climate](https://codeclimate.com/github/boza/interaction/badges/gpa.svg)](https://codeclimate.com/github/boza/interaction)
|
2
|
+
|
3
|
+
[ ![Codeship Status for boza/interaction](https://codeship.com/projects/bfb931b0-fb51-0132-06e2-1658e61aa1b1/status?branch=master)](https://codeship.com/projects/87156)
|
4
|
+
|
1
5
|
# Interaction
|
2
6
|
|
3
7
|
Interactions are meant to keep controllers and models or any other business logic slim (YAY).
|
data/lib/simple_interaction.rb
CHANGED
@@ -6,21 +6,21 @@ require "simple_interaction/class_methods"
|
|
6
6
|
module SimpleInteraction
|
7
7
|
|
8
8
|
# = Simple Interaction
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Interactions are meant to keep controllers and models slim (YAY).
|
11
11
|
# Keep intention of class clear when using interactions
|
12
12
|
# for example to create a user a class should be name Users::Create.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
#
|
15
15
|
# example of usage:
|
16
16
|
#
|
17
17
|
# class Klass
|
18
18
|
# include Interaction
|
19
|
-
#
|
20
|
-
# requires :param1, :param2
|
19
|
+
#
|
20
|
+
# requires :param1, :param2
|
21
21
|
#
|
22
22
|
# private
|
23
|
-
#
|
23
|
+
#
|
24
24
|
# def run
|
25
25
|
# method
|
26
26
|
# end
|
@@ -32,10 +32,9 @@ module SimpleInteraction
|
|
32
32
|
# end
|
33
33
|
#
|
34
34
|
# Klass.run(param1: param1, param2: param2)
|
35
|
-
|
35
|
+
|
36
36
|
def self.included(receiver)
|
37
37
|
receiver.extend ClassMethods
|
38
38
|
receiver.send :prepend, InstanceMethods
|
39
39
|
end
|
40
|
-
|
41
|
-
end
|
40
|
+
end
|
@@ -12,7 +12,7 @@ module SimpleInteraction
|
|
12
12
|
def requirements
|
13
13
|
@requirements ||= []
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
# specifies the error class that will be raise if interaction is run with !
|
17
17
|
# if nothing is set InteractionError will be the default error class
|
18
18
|
def fail_with(klass)
|
@@ -52,9 +52,8 @@ module SimpleInteraction
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def set_requirements(attrs)
|
55
|
-
|
55
|
+
attr_reader *attrs
|
56
56
|
requirements.unshift(*attrs)
|
57
57
|
end
|
58
|
-
|
59
|
-
end
|
58
|
+
end
|
60
59
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
module SimpleInteraction
|
2
|
-
|
3
2
|
#main interaction error class
|
4
3
|
class InteractionError< StandardError;end
|
5
4
|
|
@@ -8,5 +7,4 @@ module SimpleInteraction
|
|
8
7
|
|
9
8
|
# this exception will be raised if no run method is implemented on the interaction class
|
10
9
|
class NotImplemented < InteractionError;end
|
11
|
-
|
12
10
|
end
|
@@ -16,7 +16,16 @@ module SimpleInteraction
|
|
16
16
|
# sets the attr_accessor for each requirement of the intereaction
|
17
17
|
def initialize(**opts)
|
18
18
|
opts.select { |option, _| self.class.requirements.include?(option) }.each do |accessor, value|
|
19
|
-
|
19
|
+
instance_variable_set("@#{accessor}", value)
|
20
|
+
opts.delete(accessor)
|
21
|
+
end
|
22
|
+
set_optional_data(opts)
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_optional_data(opts)
|
26
|
+
@optional_params = {}
|
27
|
+
opts.each do |key, value|
|
28
|
+
@optional_params[key] = value
|
20
29
|
end
|
21
30
|
end
|
22
31
|
|
@@ -27,7 +36,6 @@ module SimpleInteraction
|
|
27
36
|
if success?
|
28
37
|
@result = interaction_run
|
29
38
|
end
|
30
|
-
end
|
31
|
-
|
39
|
+
end
|
32
40
|
end
|
33
41
|
end
|
data/test/interaction_test.rb
CHANGED
@@ -46,7 +46,7 @@ module SimpleInteraction
|
|
46
46
|
|
47
47
|
def test_success
|
48
48
|
interaction = Interactor.run(param: 'awesome interaction')
|
49
|
-
assert interaction.success?, "Interactor didn't finish successfuly #{interaction.error}"
|
49
|
+
assert interaction.success?, "Interactor didn't finish successfuly #{interaction.error}"
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_run_with_bang
|
@@ -55,7 +55,7 @@ module SimpleInteraction
|
|
55
55
|
|
56
56
|
def test_error
|
57
57
|
interaction = Interactor.run(param: '1')
|
58
|
-
refute interaction.success?, 'Interactor didn\'t finish with an error'
|
58
|
+
refute interaction.success?, 'Interactor didn\'t finish with an error'
|
59
59
|
assert_match interaction.error, "only strings please"
|
60
60
|
end
|
61
61
|
|
@@ -68,7 +68,7 @@ module SimpleInteraction
|
|
68
68
|
assert_raises(SimpleInteraction::NotImplemented) { InteractorNotImplemented.run(param: '1') }
|
69
69
|
end
|
70
70
|
|
71
|
-
end
|
71
|
+
end
|
72
72
|
end
|
73
73
|
|
74
74
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_interaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jose Boza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
77
|
version: '0'
|
78
78
|
requirements: []
|
79
79
|
rubyforge_project:
|
80
|
-
rubygems_version: 2.
|
80
|
+
rubygems_version: 2.4.5.1
|
81
81
|
signing_key:
|
82
82
|
specification_version: 4
|
83
83
|
summary: Keep your code clean with simple interactions
|