lean_interactor 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/Makefile +8 -5
- data/README.md +39 -28
- data/lib/lean_interactor/version.rb +1 -1
- data/lib/lean_interactor.rb +18 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e386d723035689112cf60bb40c222c03d1d418af
|
4
|
+
data.tar.gz: 915ee3699070a92ca364289c2c00fc6a6b6b94e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3af4a1b194dd3b29fa2aa89e5a636d0397a93528c3676c619466c9b65483ac804acd3f7d7f19896c23a8ab4365db02f28db155677b7317d6ed6fee007c310774
|
7
|
+
data.tar.gz: 7716531b33cb78891ffaf496dfc8623c6304a43b5609f3b70548c34a62cf9636a9abaf6251c02990e95a4f8c62a1da977fb4690f73707933a1459d5e1d187150
|
data/Gemfile.lock
CHANGED
data/Makefile
CHANGED
data/README.md
CHANGED
@@ -1,38 +1,32 @@
|
|
1
1
|
# LeanInteractor
|
2
2
|
|
3
|
-
Interactor is a stateless class intended to do one action. It is like function in functional languages.
|
3
|
+
Interactor is a stateless class intended to do one action. It is like function in functional languages.
|
4
4
|
|
5
|
-
|
6
|
-
```ruby
|
7
|
-
class Emails::Send
|
8
|
-
def self.for(user)
|
9
|
-
new(user).run
|
10
|
-
end
|
5
|
+
If you are working with Rails, interactor is a perfect place to put your bussines logic and keep controllers and models light and clean.
|
11
6
|
|
12
|
-
|
7
|
+
## Usage
|
13
8
|
|
14
|
-
|
15
|
-
@user = user
|
16
|
-
end
|
9
|
+
Include `LeanInteractor` to your class and define `run` method:
|
17
10
|
|
18
|
-
def run
|
19
|
-
# email sending logic goes here
|
20
|
-
end
|
21
|
-
```
|
22
|
-
|
23
|
-
##### With LeanInteractor
|
24
11
|
```ruby
|
25
|
-
class
|
12
|
+
class Users::Create
|
26
13
|
include LeanInteractor
|
27
14
|
|
28
|
-
|
15
|
+
initialize_call :user_params
|
29
16
|
|
30
17
|
def run
|
31
|
-
#
|
18
|
+
# user creation logic goes here
|
32
19
|
end
|
33
20
|
end
|
34
21
|
```
|
35
22
|
|
23
|
+
And then call your interactor:
|
24
|
+
```ruby
|
25
|
+
Users::Create.call(user_params)
|
26
|
+
```
|
27
|
+
|
28
|
+
`LeanInteractor` provides three helper methods: `initialize_call`, `initialize_run` and `initialize_for`. They generate corresponding execution methods: `call`, `run` and `for`. Use them depending on your preference.
|
29
|
+
|
36
30
|
## Installation
|
37
31
|
|
38
32
|
Add this line to your application's Gemfile:
|
@@ -49,25 +43,42 @@ Or install it yourself as:
|
|
49
43
|
|
50
44
|
$ gem install lean_interactor
|
51
45
|
|
52
|
-
##
|
46
|
+
## Motivation
|
53
47
|
|
54
|
-
|
48
|
+
This gem was created to reduce amount of the boilerplate code needed to define an interactor:
|
49
|
+
|
50
|
+
##### Without LeanInteractor
|
55
51
|
|
56
52
|
```ruby
|
57
|
-
class
|
58
|
-
|
53
|
+
class Users::Create
|
54
|
+
def self.for(user_params)
|
55
|
+
new(user_params).run
|
56
|
+
end
|
59
57
|
|
60
|
-
|
58
|
+
attr_reader :user_params
|
59
|
+
|
60
|
+
def initialize(user_params)
|
61
|
+
@user_params = user_params
|
62
|
+
end
|
61
63
|
|
62
64
|
def run
|
63
|
-
#
|
65
|
+
# user creation logic goes here
|
64
66
|
end
|
65
67
|
end
|
66
68
|
```
|
67
69
|
|
68
|
-
|
70
|
+
##### With LeanInteractor
|
71
|
+
|
69
72
|
```ruby
|
70
|
-
|
73
|
+
class Users::Create
|
74
|
+
include LeanInteractor
|
75
|
+
|
76
|
+
initialize_for :user_params
|
77
|
+
|
78
|
+
def run
|
79
|
+
# user creation logic goes here
|
80
|
+
end
|
81
|
+
end
|
71
82
|
```
|
72
83
|
|
73
84
|
## Development
|
data/lib/lean_interactor.rb
CHANGED
@@ -5,14 +5,29 @@ require 'lean_interactor/version'
|
|
5
5
|
module LeanInteractor
|
6
6
|
def self.included(base)
|
7
7
|
base.extend(ClassMethods)
|
8
|
-
eval LeanInteractor::GenerateMainMethod.for(:base, :run, [])
|
9
8
|
end
|
10
9
|
|
11
10
|
module ClassMethods
|
12
|
-
def
|
11
|
+
def initialize_for(*argument_names)
|
12
|
+
initialize_method(:for, argument_names)
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize_run(*argument_names)
|
16
|
+
initialize_method(:run, argument_names)
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize_call(*argument_names)
|
20
|
+
initialize_method(:call, argument_names)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def initialize_method(method_name, argument_names)
|
13
26
|
attr_reader(*argument_names)
|
14
|
-
eval LeanInteractor::GenerateMainMethod.for(:self,
|
27
|
+
eval LeanInteractor::GenerateMainMethod.for(:self, method_name, argument_names)
|
15
28
|
eval LeanInteractor::GenerateInitializeMethod.for(argument_names)
|
29
|
+
|
30
|
+
true
|
16
31
|
end
|
17
32
|
end
|
18
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lean_interactor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justas Kazakauskas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,3 +100,4 @@ signing_key:
|
|
100
100
|
specification_version: 4
|
101
101
|
summary: LeanInteractor reduces boilerplate code while defining interactor classes
|
102
102
|
test_files: []
|
103
|
+
has_rdoc:
|