injectable 2.1.0 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +9 -0
- data/.github/workflows/ruby.yml +6 -7
- data/.rubocop.yml +5 -0
- data/.ruby-version +1 -0
- data/.travis.yml +2 -2
- data/CHANGELOG.md +16 -5
- data/Gemfile.lock +20 -20
- data/README.md +3 -1
- data/injectable.gemspec +3 -3
- data/lib/injectable/dependency.rb +39 -7
- data/lib/injectable/version.rb +1 -1
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bc8a40afa4124a664ec446747c818776a36ffbc92e66bbdd57e4d3305dfc579
|
4
|
+
data.tar.gz: e71fe4d221658bb9b0881f93daeec3be8fed0e5c84c87b8c7e13b2cd6780532f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ebf03dd89932ae9adade059861d781ef0e628fc2118ddda57824313094368d34e2b56683931a4aa3316c405d490d14109e8e30eb47bcacd7413c6f7a16dcf12
|
7
|
+
data.tar.gz: 717766ec123434962d2847b4a43307fdc6a17a1d04d82d0643e49741e0b52e09a7e8d1b902046078fe2ced8849573e7af8ab834a555b989c459e89598be3de66
|
data/.editorconfig
ADDED
data/.github/workflows/ruby.yml
CHANGED
@@ -10,16 +10,15 @@ jobs:
|
|
10
10
|
build:
|
11
11
|
runs-on: ubuntu-latest
|
12
12
|
strategy:
|
13
|
+
fail-fast: false
|
13
14
|
matrix:
|
14
|
-
ruby: [
|
15
|
+
ruby: ['3.0.5', '3.1.3', '3.2.1']
|
15
16
|
steps:
|
16
|
-
- uses: actions/checkout@
|
17
|
+
- uses: actions/checkout@v3
|
17
18
|
- name: Set up Ruby ${{ matrix.ruby }}
|
18
|
-
uses:
|
19
|
+
uses: ruby/setup-ruby@v1
|
19
20
|
with:
|
20
21
|
ruby-version: ${{ matrix.ruby }}
|
22
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
21
23
|
- name: Build and test with Rake
|
22
|
-
run:
|
23
|
-
gem install bundler
|
24
|
-
bundle install --jobs 4 --retry 3
|
25
|
-
bundle exec rake
|
24
|
+
run: bundle exec rake
|
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.1
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,17 +1,28 @@
|
|
1
|
-
|
1
|
+
# Unreleased
|
2
2
|
|
3
|
-
|
3
|
+
## 2.1.2 - 2023-03-31
|
4
|
+
|
5
|
+
* Drop support for Ruby 2.7
|
6
|
+
* Add Ruby 3.2.1 to test matrix
|
7
|
+
* Updates Github Actions versions for checkout and Ruby setup
|
8
|
+
|
9
|
+
## 2.1.1 - 2021-03-15
|
10
|
+
|
11
|
+
* bug fixes
|
12
|
+
* Address final Ruby 2.7 warnings (#24)
|
13
|
+
|
14
|
+
## 2.1.0 - 2021-01-05
|
4
15
|
|
5
16
|
* enhancements
|
6
17
|
* Return `method` object instead of monkey patched instance (#17)
|
7
18
|
* Prepare for Ruby 3.0 (#22)
|
8
19
|
|
9
|
-
|
20
|
+
## 2.0.0 - 2020-03-16
|
10
21
|
|
11
22
|
* breaking changes
|
12
23
|
* Raises exception if shadowing an existing `#call` method in a dependency (#15)
|
13
24
|
|
14
|
-
|
25
|
+
## 1.0.3 - 2020-03-16
|
15
26
|
|
16
27
|
* enhancements
|
17
28
|
* Added GitHub Actions as CI (#9)
|
@@ -19,7 +30,7 @@
|
|
19
30
|
* bug fixes
|
20
31
|
* Fixed a bug that wouldn't pass a block if `#call` was aliased (#7)
|
21
32
|
|
22
|
-
|
33
|
+
## 1.0.2 - 2020-03-02
|
23
34
|
|
24
35
|
* security
|
25
36
|
* Bump `rake` to 12.3.3 (#11)
|
data/Gemfile.lock
CHANGED
@@ -1,45 +1,45 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
injectable (2.1.
|
4
|
+
injectable (2.1.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
byebug (11.1.3)
|
10
10
|
coderay (1.1.3)
|
11
|
-
diff-lcs (1.
|
11
|
+
diff-lcs (1.5.0)
|
12
12
|
method_source (1.0.0)
|
13
|
-
pry (0.
|
13
|
+
pry (0.14.2)
|
14
14
|
coderay (~> 1.1)
|
15
15
|
method_source (~> 1.0)
|
16
|
-
pry-byebug (3.
|
16
|
+
pry-byebug (3.10.1)
|
17
17
|
byebug (~> 11.0)
|
18
|
-
pry (
|
19
|
-
rake (13.0.
|
20
|
-
rspec (3.
|
21
|
-
rspec-core (~> 3.
|
22
|
-
rspec-expectations (~> 3.
|
23
|
-
rspec-mocks (~> 3.
|
24
|
-
rspec-core (3.
|
25
|
-
rspec-support (~> 3.
|
26
|
-
rspec-expectations (3.
|
18
|
+
pry (>= 0.13, < 0.15)
|
19
|
+
rake (13.0.6)
|
20
|
+
rspec (3.12.0)
|
21
|
+
rspec-core (~> 3.12.0)
|
22
|
+
rspec-expectations (~> 3.12.0)
|
23
|
+
rspec-mocks (~> 3.12.0)
|
24
|
+
rspec-core (3.12.1)
|
25
|
+
rspec-support (~> 3.12.0)
|
26
|
+
rspec-expectations (3.12.2)
|
27
27
|
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.
|
29
|
-
rspec-mocks (3.
|
28
|
+
rspec-support (~> 3.12.0)
|
29
|
+
rspec-mocks (3.12.3)
|
30
30
|
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
-
rspec-support (~> 3.
|
32
|
-
rspec-support (3.
|
31
|
+
rspec-support (~> 3.12.0)
|
32
|
+
rspec-support (3.12.0)
|
33
33
|
|
34
34
|
PLATFORMS
|
35
35
|
ruby
|
36
36
|
|
37
37
|
DEPENDENCIES
|
38
|
-
bundler (~> 2.
|
38
|
+
bundler (~> 2.4)
|
39
39
|
injectable!
|
40
40
|
pry-byebug
|
41
41
|
rake (~> 13.0)
|
42
|
-
rspec (~> 3.
|
42
|
+
rspec (~> 3.11)
|
43
43
|
|
44
44
|
BUNDLED WITH
|
45
|
-
2.
|
45
|
+
2.4.6
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
`Injectable` is an opinionated and declarative [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection) library for ruby.
|
6
6
|
|
7
|
-
It is being used in production (under ruby
|
7
|
+
It is being used in production (under ruby 3.1) in [RubiconMD](https://github.com/rubiconmd) and was extracted from its codebase.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -339,6 +339,8 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
339
339
|
|
340
340
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
341
341
|
|
342
|
+
Please consider configuring [https://editorconfig.org/] on your favourite IDE/editor, so basic file formatting is consistent and avoids cross-platform issues. Some editors require [a plugin](https://editorconfig.org/#download), meanwhile others have it [pre-installed](https://editorconfig.org/#pre-installed).
|
343
|
+
|
342
344
|
## Contributing
|
343
345
|
|
344
346
|
Bug reports and pull requests are welcome on GitHub at https://github.com/rubiconmd/injectable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
data/injectable.gemspec
CHANGED
@@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.bindir = 'exe'
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ['lib']
|
23
|
-
spec.required_ruby_version = '>=
|
23
|
+
spec.required_ruby_version = '>= 3.0'
|
24
24
|
|
25
|
-
spec.add_development_dependency 'bundler', '~> 2.
|
25
|
+
spec.add_development_dependency 'bundler', '~> 2.4'
|
26
26
|
spec.add_development_dependency 'pry-byebug'
|
27
27
|
spec.add_development_dependency 'rake', '~> 13.0'
|
28
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.11'
|
29
29
|
end
|
@@ -2,15 +2,34 @@ module Injectable
|
|
2
2
|
# Initialize a dependency based on the options or the block passed
|
3
3
|
Dependency = Struct.new(:name, :block, :class, :call, :with, :depends_on, keyword_init: true) do
|
4
4
|
def instance(args: [], namespace: nil)
|
5
|
-
|
6
|
-
|
5
|
+
positional_args, kwargs = split_args(args)
|
6
|
+
|
7
|
+
wrap_call build_instance(positional_args, kwargs, namespace: namespace)
|
7
8
|
end
|
8
9
|
|
9
10
|
private
|
10
11
|
|
11
|
-
def
|
12
|
+
def split_args(args)
|
13
|
+
args = preprocess_args(args)
|
14
|
+
|
15
|
+
return [[], {}] if args.empty?
|
16
|
+
|
17
|
+
kwargs = args.pop
|
18
|
+
|
19
|
+
if kwargs.is_a?(Hash) && kwargs.keys.all? { |key| key.is_a?(Symbol) }
|
20
|
+
[args, kwargs]
|
21
|
+
else
|
22
|
+
[args << kwargs, {}]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def preprocess_args(args)
|
12
27
|
args = with unless with.nil?
|
13
|
-
args
|
28
|
+
wrap_args(args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def wrap_args(args)
|
32
|
+
args.is_a?(Array) ? args.clone : [args]
|
14
33
|
end
|
15
34
|
|
16
35
|
def wrap_call(the_instance)
|
@@ -23,10 +42,17 @@ module Injectable
|
|
23
42
|
the_instance.public_method(call)
|
24
43
|
end
|
25
44
|
|
26
|
-
def build_instance(args, namespace:)
|
27
|
-
return
|
45
|
+
def build_instance(args, kwargs, namespace:)
|
46
|
+
return build_instance_26(args, kwargs, namespace: namespace) if RUBY_VERSION < '2.7'
|
28
47
|
|
29
|
-
block.
|
48
|
+
instantiator = block || klass(namespace: namespace).method(:new)
|
49
|
+
if kwargs.empty?
|
50
|
+
# otherwise an empty hash will be added in ruby 2.7, which could be taken as
|
51
|
+
# positional argument instead.
|
52
|
+
instantiator.call(*args)
|
53
|
+
else
|
54
|
+
instantiator.call(*args, **kwargs)
|
55
|
+
end
|
30
56
|
end
|
31
57
|
|
32
58
|
def klass(namespace:)
|
@@ -40,5 +66,11 @@ module Injectable
|
|
40
66
|
def camelcased
|
41
67
|
@camelcased ||= name.to_s.split('_').map(&:capitalize).join
|
42
68
|
end
|
69
|
+
|
70
|
+
def build_instance_26(args, kwargs, namespace:)
|
71
|
+
args << kwargs if kwargs.any?
|
72
|
+
|
73
|
+
block.nil? ? klass(namespace: namespace).new(*args) : block.call(*args)
|
74
|
+
end
|
43
75
|
end
|
44
76
|
end
|
data/lib/injectable/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: injectable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Papipo
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: exe
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2023-03-30 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bundler
|
@@ -20,14 +20,14 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - "~>"
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: '2.
|
23
|
+
version: '2.4'
|
24
24
|
type: :development
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
requirements:
|
28
28
|
- - "~>"
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: '2.
|
30
|
+
version: '2.4'
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: pry-byebug
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,14 +62,14 @@ dependencies:
|
|
62
62
|
requirements:
|
63
63
|
- - "~>"
|
64
64
|
- !ruby/object:Gem::Version
|
65
|
-
version: '3.
|
65
|
+
version: '3.11'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
68
|
version_requirements: !ruby/object:Gem::Requirement
|
69
69
|
requirements:
|
70
70
|
- - "~>"
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version: '3.
|
72
|
+
version: '3.11'
|
73
73
|
description:
|
74
74
|
email:
|
75
75
|
- dev@rubiconmd.com
|
@@ -77,9 +77,12 @@ executables: []
|
|
77
77
|
extensions: []
|
78
78
|
extra_rdoc_files: []
|
79
79
|
files:
|
80
|
+
- ".editorconfig"
|
80
81
|
- ".github/workflows/ruby.yml"
|
81
82
|
- ".gitignore"
|
82
83
|
- ".rspec"
|
84
|
+
- ".rubocop.yml"
|
85
|
+
- ".ruby-version"
|
83
86
|
- ".travis.yml"
|
84
87
|
- CHANGELOG.md
|
85
88
|
- CODE_OF_CONDUCT.md
|
@@ -112,14 +115,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
112
115
|
requirements:
|
113
116
|
- - ">="
|
114
117
|
- !ruby/object:Gem::Version
|
115
|
-
version: '
|
118
|
+
version: '3.0'
|
116
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
120
|
requirements:
|
118
121
|
- - ">="
|
119
122
|
- !ruby/object:Gem::Version
|
120
123
|
version: '0'
|
121
124
|
requirements: []
|
122
|
-
rubygems_version: 3.
|
125
|
+
rubygems_version: 3.4.7
|
123
126
|
signing_key:
|
124
127
|
specification_version: 4
|
125
128
|
summary: A library to help you build nice service objects with dependency injection.
|