interactor-initializer 0.2.0 → 1.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 +5 -5
- data/.github/workflows/build_release_pipeline.yaml +53 -0
- data/.ruby-version +1 -0
- data/LICENSE +21 -0
- data/README.md +0 -1
- data/Rakefile +4 -0
- data/interactor-initializer.gemspec +3 -2
- data/lib/interactor/initializer/helper.rb +62 -0
- data/lib/interactor/initializer/version.rb +1 -1
- data/lib/interactor/initializer.rb +11 -8
- data/spec/{initializer/attr_readers_spec.rb → interactor/initializer/helper_spec.rb} +7 -4
- data/spec/interactor/initializer_spec.rb +109 -0
- metadata +17 -18
- data/.travis.yml +0 -4
- data/lib/interactor/initializer/attr_readers.rb +0 -10
- data/lib/interactor/initializer/call_methods.rb +0 -9
- data/lib/interactor/initializer/initialize.rb +0 -35
- data/spec/initializer/call_methods_spec.rb +0 -13
- data/spec/initializer/initialize_spec.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2a7524207f17039e7eda3b4e2ceb0a3f406c70da99c7776be2a3d042dd6dc474
|
4
|
+
data.tar.gz: 23377afbee95423b6cab13e9d58137c1319e24bcefb7754b32a225308b28c09f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9533cbdd913a94086ec11affcb130704ac4f7603468aa5881f2dd1c0c2aa87132dda21e13f2ceedd8fccf993d006cf6fd8af0d89b34331ae691e467b4201b8ba
|
7
|
+
data.tar.gz: 26f239fb44ac1a598cfe05eff32a0ba53ff8ac25c4dd1b06398ace36e38613e4d239c0fa800fa02d74158912d835639b51399d0a8b2687deb4b0db1226a860d1
|
@@ -0,0 +1,53 @@
|
|
1
|
+
name: Build and release ruby gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches: [ master ]
|
6
|
+
push:
|
7
|
+
workflow_dispatch:
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build-release-pipeline:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
container: ruby:2.7.2
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v2
|
15
|
+
- name: Setup
|
16
|
+
run: |
|
17
|
+
gem install bundler
|
18
|
+
bundle install
|
19
|
+
|
20
|
+
- name: Test
|
21
|
+
run: bundle exec rspec
|
22
|
+
|
23
|
+
- name: Build
|
24
|
+
id: build
|
25
|
+
if: success() && github.ref == 'refs/heads/master'
|
26
|
+
run: |
|
27
|
+
bundle exec rake build
|
28
|
+
echo "::set-output name=gem_version::v$(bundle exec rake version)"
|
29
|
+
|
30
|
+
- name: Release
|
31
|
+
if: success() && github.ref == 'refs/heads/master'
|
32
|
+
run: |
|
33
|
+
mkdir -p $HOME/.gem
|
34
|
+
touch $HOME/.gem/credentials
|
35
|
+
chmod 600 $HOME/.gem/credentials
|
36
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
37
|
+
gem push pkg/*
|
38
|
+
env:
|
39
|
+
GEM_HOST_API_KEY: "${{ secrets.RUBYGEMS_AUTH_TOKEN }}"
|
40
|
+
|
41
|
+
- name: Tag repo with new gem version
|
42
|
+
if: success() && github.ref == 'refs/heads/master'
|
43
|
+
uses: actions/github-script@v3
|
44
|
+
with:
|
45
|
+
github-token: ${{ github.token }}
|
46
|
+
script: |
|
47
|
+
github.git.createRef({
|
48
|
+
owner: context.repo.owner,
|
49
|
+
repo: context.repo.repo,
|
50
|
+
ref: "refs/tags/${{ steps.build.outputs.gem_version }}",
|
51
|
+
sha: context.sha
|
52
|
+
})
|
53
|
+
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.2
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 Vinted
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
[](http://travis-ci.org/vinted/interactor-initializer)
|
4
4
|
[](http://badge.fury.io/rb/interactor-initializer)
|
5
|
-
[](https://gemnasium.com/vinted/interactor-initializer)
|
6
5
|
|
7
6
|
Dry interactor initializer
|
8
7
|
|
data/Rakefile
CHANGED
@@ -8,15 +8,16 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.platform = Gem::Platform::RUBY
|
9
9
|
spec.version = Interactor::Initializer::VERSION
|
10
10
|
spec.authors = ['Šarūnas Kūjalis']
|
11
|
-
spec.email = ['
|
11
|
+
spec.email = ['admin@vinted.com']
|
12
12
|
spec.summary = 'Dry interactor initializer'
|
13
13
|
spec.homepage = 'https://github.com/vinted/interactor-initializer'
|
14
|
+
spec.license = 'MIT'
|
14
15
|
|
15
16
|
spec.files = `git ls-files`.split($/)
|
16
17
|
spec.test_files = `git ls-files -- {spec}/*`.split("\n")
|
17
18
|
spec.require_paths = ['lib']
|
18
19
|
|
19
|
-
spec.add_development_dependency 'bundler'
|
20
|
+
spec.add_development_dependency 'bundler'
|
20
21
|
spec.add_development_dependency 'rake', '~> 10.0'
|
21
22
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
22
23
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Interactor::Initializer::Helper
|
4
|
+
def self.modify_class(target_class, signature, attributes, class_methods)
|
5
|
+
assignments = attr_assignments(attributes)
|
6
|
+
|
7
|
+
target_class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
8
|
+
def initialize(#{signature})
|
9
|
+
#{assignments}
|
10
|
+
end
|
11
|
+
|
12
|
+
#{class_methods}
|
13
|
+
RUBY
|
14
|
+
|
15
|
+
attr_readers(target_class, attributes)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.attr_readers(target_class, attributes)
|
19
|
+
target_class.class_eval do
|
20
|
+
attributes.each do |attr|
|
21
|
+
attr_reader(attr)
|
22
|
+
protected(attr)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.methods_with_params
|
28
|
+
<<-RUBY
|
29
|
+
def self.for(*args)
|
30
|
+
new(*args).run
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.run(*args)
|
34
|
+
new(*args).run
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.with(*args)
|
38
|
+
new(*args).run
|
39
|
+
end
|
40
|
+
RUBY
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.methods_with_keywords
|
44
|
+
<<-RUBY
|
45
|
+
def self.for(args)
|
46
|
+
new(**args).run
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.run(args)
|
50
|
+
new(**args).run
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.with(args)
|
54
|
+
new(**args).run
|
55
|
+
end
|
56
|
+
RUBY
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.attr_assignments(attributes)
|
60
|
+
attributes.map { |attr| "@#{attr} = #{attr}" }.join(';')
|
61
|
+
end
|
62
|
+
end
|
@@ -1,26 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'interactor/initializer/version'
|
2
|
-
require 'interactor/initializer/
|
3
|
-
require 'interactor/initializer/call_methods'
|
4
|
-
require 'interactor/initializer/initialize'
|
4
|
+
require 'interactor/initializer/helper'
|
5
5
|
|
6
6
|
module Interactor
|
7
7
|
module Initializer
|
8
8
|
def self.included(target_class)
|
9
9
|
target_class.extend ClassMethods
|
10
|
-
Interactor::Initializer::CallMethods.for(target_class)
|
11
10
|
end
|
12
11
|
|
13
12
|
module ClassMethods
|
14
13
|
module_function
|
15
14
|
|
16
15
|
def initialize_with(*attributes)
|
17
|
-
|
18
|
-
Interactor::Initializer::
|
16
|
+
signature = attributes.join(', ')
|
17
|
+
class_methods = Interactor::Initializer::Helper.methods_with_params
|
18
|
+
|
19
|
+
Interactor::Initializer::Helper.modify_class(self, signature, attributes, class_methods)
|
19
20
|
end
|
20
21
|
|
21
22
|
def initialize_with_keyword_params(*attributes)
|
22
|
-
|
23
|
-
Interactor::Initializer::
|
23
|
+
signature = attributes.map { |attr| "#{attr}:" }.join(', ')
|
24
|
+
class_methods = Interactor::Initializer::Helper.methods_with_keywords
|
25
|
+
|
26
|
+
Interactor::Initializer::Helper.modify_class(self, signature, attributes, class_methods)
|
24
27
|
end
|
25
28
|
end
|
26
29
|
end
|
@@ -1,8 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe Interactor::Initializer::Helper do
|
4
|
+
describe '.attr_readers' do
|
5
|
+
subject { described_class.attr_readers(dummy_class, attributes) }
|
6
|
+
|
4
7
|
let(:dummy_class) { Class.new }
|
5
|
-
let(:attributes) { [
|
8
|
+
let(:attributes) { %i[test1 test2] }
|
6
9
|
|
7
10
|
it 'adds protected attr_reader' do
|
8
11
|
subject
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe Interactor::Initializer do
|
4
|
+
let(:interactor) do
|
5
|
+
Class.new do
|
6
|
+
include Interactor::Initializer
|
7
|
+
|
8
|
+
initialize_with :arg1, :arg2
|
9
|
+
|
10
|
+
def run
|
11
|
+
:result
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
let(:params) { %w[value1 value2] }
|
16
|
+
|
17
|
+
describe '.for' do
|
18
|
+
subject { interactor.for(*params) }
|
19
|
+
|
20
|
+
it { is_expected.to eq(:result) }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.with' do
|
24
|
+
subject { interactor.with(*params) }
|
25
|
+
|
26
|
+
it { is_expected.to eq(:result) }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.run' do
|
30
|
+
subject { interactor.run(*params) }
|
31
|
+
|
32
|
+
it { is_expected.to eq(:result) }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '.new' do
|
36
|
+
subject { interactor.new(*params) }
|
37
|
+
|
38
|
+
it 'adds instance variables' do
|
39
|
+
expect(subject.instance_variable_get(:@arg1)).to eq 'value1'
|
40
|
+
expect(subject.instance_variable_get(:@arg2)).to eq 'value2'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when incorrect number of params' do
|
45
|
+
subject { interactor.for(*params) }
|
46
|
+
|
47
|
+
let(:params) { %w[value1] }
|
48
|
+
|
49
|
+
it 'raises an error' do
|
50
|
+
expect { subject }.to raise_error(/wrong number of arguments/)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when initialization with keywords' do
|
55
|
+
let(:interactor) do
|
56
|
+
Class.new do
|
57
|
+
include Interactor::Initializer
|
58
|
+
|
59
|
+
initialize_with_keyword_params :arg1, :arg2
|
60
|
+
|
61
|
+
def run
|
62
|
+
:result
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
let(:params) do
|
67
|
+
{ arg1: 'value1', arg2: 'value2' }
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '.for' do
|
71
|
+
subject { interactor.for(params) }
|
72
|
+
|
73
|
+
it { is_expected.to eq(:result) }
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '.with' do
|
77
|
+
subject { interactor.with(params) }
|
78
|
+
|
79
|
+
it { is_expected.to eq(:result) }
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '.run' do
|
83
|
+
subject { interactor.run(params) }
|
84
|
+
|
85
|
+
it { is_expected.to eq(:result) }
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '.new' do
|
89
|
+
subject { interactor.new(**params) }
|
90
|
+
|
91
|
+
it 'adds instance variables' do
|
92
|
+
expect(subject.instance_variable_get(:@arg1)).to eq 'value1'
|
93
|
+
expect(subject.instance_variable_get(:@arg2)).to eq 'value2'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when incorrect keywords' do
|
98
|
+
subject { interactor.for(params) }
|
99
|
+
|
100
|
+
let(:params) do
|
101
|
+
{ arg1: 'value2', arg4: 'value2' }
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'raises an error' do
|
105
|
+
expect { subject }.to raise_error(/missing keyword: :arg2/)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: interactor-initializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '1.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Šarūnas Kūjalis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -54,30 +54,30 @@ dependencies:
|
|
54
54
|
version: '3.0'
|
55
55
|
description:
|
56
56
|
email:
|
57
|
-
-
|
57
|
+
- admin@vinted.com
|
58
58
|
executables: []
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".github/workflows/build_release_pipeline.yaml"
|
62
63
|
- ".gitignore"
|
63
64
|
- ".rspec"
|
64
65
|
- ".rubocop.yml"
|
65
|
-
- ".
|
66
|
+
- ".ruby-version"
|
66
67
|
- Gemfile
|
68
|
+
- LICENSE
|
67
69
|
- README.md
|
68
70
|
- Rakefile
|
69
71
|
- interactor-initializer.gemspec
|
70
72
|
- lib/interactor/initializer.rb
|
71
|
-
- lib/interactor/initializer/
|
72
|
-
- lib/interactor/initializer/call_methods.rb
|
73
|
-
- lib/interactor/initializer/initialize.rb
|
73
|
+
- lib/interactor/initializer/helper.rb
|
74
74
|
- lib/interactor/initializer/version.rb
|
75
|
-
- spec/initializer/
|
76
|
-
- spec/
|
77
|
-
- spec/initializer/initialize_spec.rb
|
75
|
+
- spec/interactor/initializer/helper_spec.rb
|
76
|
+
- spec/interactor/initializer_spec.rb
|
78
77
|
- spec/spec_helper.rb
|
79
78
|
homepage: https://github.com/vinted/interactor-initializer
|
80
|
-
licenses:
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
81
|
metadata: {}
|
82
82
|
post_install_message:
|
83
83
|
rdoc_options: []
|
@@ -94,8 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
|
-
|
98
|
-
rubygems_version: 2.4.5
|
97
|
+
rubygems_version: 3.1.4
|
99
98
|
signing_key:
|
100
99
|
specification_version: 4
|
101
100
|
summary: Dry interactor initializer
|
data/.travis.yml
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
class Interactor::Initializer::Initialize
|
2
|
-
def self.for(*args)
|
3
|
-
new(*args).run
|
4
|
-
end
|
5
|
-
|
6
|
-
attr_reader :target_class, :attributes, :keyword_params
|
7
|
-
|
8
|
-
def initialize(target_class, attributes, keyword_params: false)
|
9
|
-
@target_class = target_class
|
10
|
-
@attributes = attributes
|
11
|
-
@keyword_params = keyword_params
|
12
|
-
end
|
13
|
-
|
14
|
-
def run
|
15
|
-
target_class.class_eval <<-RUBY
|
16
|
-
def initialize(#{initializer_signature(attributes)})
|
17
|
-
#{attr_assignments(attributes)}
|
18
|
-
end
|
19
|
-
RUBY
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def initializer_signature(attributes)
|
25
|
-
return attributes.join(', ') unless keyword_params
|
26
|
-
|
27
|
-
attributes.map { |attribute| "#{attribute}:" }.join(', ')
|
28
|
-
end
|
29
|
-
|
30
|
-
def attr_assignments(attributes)
|
31
|
-
attributes.inject('') do |assignments, attribute|
|
32
|
-
"#{assignments}@#{attribute} = #{attribute};"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
describe Interactor::Initializer::CallMethods do
|
2
|
-
describe '.for' do
|
3
|
-
subject { described_class.for(dummy_class) }
|
4
|
-
let(:dummy_class) { Class.new }
|
5
|
-
|
6
|
-
it 'adds .for .with and .run class methods' do
|
7
|
-
subject
|
8
|
-
expect(dummy_class).to respond_to :for
|
9
|
-
expect(dummy_class).to respond_to :with
|
10
|
-
expect(dummy_class).to respond_to :run
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
describe Interactor::Initializer::Initialize do
|
2
|
-
describe '.for' do
|
3
|
-
subject { described_class.for(dummy_class, attributes, keyword_params: keyword_params) }
|
4
|
-
let(:dummy_class) { Class.new }
|
5
|
-
let(:attributes) { [:test1, :test2] }
|
6
|
-
let(:keyword_params) { false }
|
7
|
-
|
8
|
-
shared_examples 'object initializer' do
|
9
|
-
it 'adds object initializer' do
|
10
|
-
subject
|
11
|
-
expect(dummy_instance.instance_variable_get(:@test1)).to eq 1
|
12
|
-
expect(dummy_instance.instance_variable_get(:@test2)).to eq 2
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it_behaves_like 'object initializer' do
|
17
|
-
let(:dummy_instance) { dummy_class.new(1, 2) }
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'when keyword params' do
|
21
|
-
let(:keyword_params) { true }
|
22
|
-
|
23
|
-
it_behaves_like 'object initializer' do
|
24
|
-
let(:dummy_instance) { dummy_class.new(test1: 1, test2: 2) }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|