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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c50edc0cf5c6e91b20bf9913c3a9e59ac2da7078
4
- data.tar.gz: 608b69f754e946155c5630c0522665c1bba55f9f
3
+ metadata.gz: e386d723035689112cf60bb40c222c03d1d418af
4
+ data.tar.gz: 915ee3699070a92ca364289c2c00fc6a6b6b94e6
5
5
  SHA512:
6
- metadata.gz: e899c7c035c4d02da7105d8782fdf679b40cbf100963afd9643ed4063e4ea9da191f7d5b5013ade6d8acc0879ddb38d31da2d3148c446bcd295e06da5c02ae2a
7
- data.tar.gz: 76b6d6f65c2defe52f9ec860a0b41bbeaafcbe017fcb79f2e973ad9c58c24a24b1ba3972e5c569eebe3ec393002989fc5377d878b8390e50ea462005314d72dd
6
+ metadata.gz: 3af4a1b194dd3b29fa2aa89e5a636d0397a93528c3676c619466c9b65483ac804acd3f7d7f19896c23a8ab4365db02f28db155677b7317d6ed6fee007c310774
7
+ data.tar.gz: 7716531b33cb78891ffaf496dfc8623c6304a43b5609f3b70548c34a62cf9636a9abaf6251c02990e95a4f8c62a1da977fb4690f73707933a1459d5e1d187150
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lean_interactor (0.1.2)
4
+ lean_interactor (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/Makefile CHANGED
@@ -1,10 +1,13 @@
1
- build:
2
- rm -rf *.gem
3
- rm -rf pkg
4
- gem build lean_interactor.gemspec
5
-
6
1
  test:
7
2
  @ rspec
8
3
 
4
+ build: clear
5
+ @ bundle
6
+ @ gem build *.gemspec
7
+
9
8
  release: test build
10
9
  @ gem push *.gem
10
+
11
+ clear:
12
+ @ rm -rf pkg
13
+ @ rm -rf *.gem
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. This gem is created to reduce amount of the boilerplate code needed to define an interactor:
3
+ Interactor is a stateless class intended to do one action. It is like function in functional languages.
4
4
 
5
- ##### Without LeanInteractor
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
- attr_reader :user
7
+ ## Usage
13
8
 
14
- def initialize(user)
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 Emails::Send
12
+ class Users::Create
26
13
  include LeanInteractor
27
14
 
28
- initialize_with :user
15
+ initialize_call :user_params
29
16
 
30
17
  def run
31
- # email sending logic goes here
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
- ## Usage
46
+ ## Motivation
53
47
 
54
- Define interactor like this:
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 Emails::Send
58
- include LeanInteractor
53
+ class Users::Create
54
+ def self.for(user_params)
55
+ new(user_params).run
56
+ end
59
57
 
60
- initialize_with :user
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
- # email sending logic goes here
65
+ # user creation logic goes here
64
66
  end
65
67
  end
66
68
  ```
67
69
 
68
- And then call it:
70
+ ##### With LeanInteractor
71
+
69
72
  ```ruby
70
- Emails::Send.for(user)
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
@@ -1,3 +1,3 @@
1
1
  module LeanInteractor
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -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 initialize_with(*argument_names)
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, :for, argument_names)
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.1.2
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-03-28 00:00:00.000000000 Z
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: