injectable 1.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +25 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile.lock +26 -16
- data/README.md +7 -5
- data/injectable.gemspec +10 -9
- data/lib/injectable.rb +1 -0
- data/lib/injectable/class_methods.rb +1 -1
- data/lib/injectable/dependency.rb +7 -3
- data/lib/injectable/method_already_exists_exception.rb +4 -0
- data/lib/injectable/version.rb +1 -1
- metadata +30 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec59b943de91947c9572d9bba1473f94392e5d2629b702e10dd03e98c6bb7a3a
|
4
|
+
data.tar.gz: e7e6dc95644f502e5100c3ee2f4e23c06bc40ac453e69ae1cc66bf3d6f2de329
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85852a19057697f19140004c32eeadc49bc0cc9276bceccfe2b98a0d0a65ecbcf7e3a7ae8f9ac34267fdc0d10aacf34d163202ed6bc6cfa35baa05fbc52db150
|
7
|
+
data.tar.gz: db94ab469130da0d7c54dd6debb3c2ad0064b4cae0654fe2038bfb2bcb1e592efbf4c5ec0ccac2ff5bf6c8b3605f6331207b80c1d8c2b58d27c9f7662a72106e
|
@@ -0,0 +1,25 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby: [ 2.5.x, 2.6, 2.7.x ]
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
18
|
+
uses: actions/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: ${{ matrix.ruby }}
|
21
|
+
- name: Build and test with Rake
|
22
|
+
run: |
|
23
|
+
gem install bundler
|
24
|
+
bundle install --jobs 4 --retry 3
|
25
|
+
bundle exec rake
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
### Unreleased
|
2
|
+
|
3
|
+
### 2.1.0 - 2021-01-05
|
4
|
+
|
5
|
+
* enhancements
|
6
|
+
* Return `method` object instead of monkey patched instance (#17)
|
7
|
+
* Prepare for Ruby 3.0 (#22)
|
8
|
+
|
9
|
+
### 2.0.0 - 2020-03-16
|
10
|
+
|
11
|
+
* breaking changes
|
12
|
+
* Raises exception if shadowing an existing `#call` method in a dependency (#15)
|
13
|
+
|
14
|
+
### 1.0.3 - 2020-03-16
|
15
|
+
|
16
|
+
* enhancements
|
17
|
+
* Added GitHub Actions as CI (#9)
|
18
|
+
|
19
|
+
* bug fixes
|
20
|
+
* Fixed a bug that wouldn't pass a block if `#call` was aliased (#7)
|
21
|
+
|
22
|
+
### 1.0.2 - 2020-03-02
|
23
|
+
|
24
|
+
* security
|
25
|
+
* Bump `rake` to 12.3.3 (#11)
|
data/Gemfile.lock
CHANGED
@@ -1,26 +1,35 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
injectable (1.0
|
4
|
+
injectable (2.1.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
byebug (11.1.3)
|
10
|
+
coderay (1.1.3)
|
11
|
+
diff-lcs (1.4.4)
|
12
|
+
method_source (1.0.0)
|
13
|
+
pry (0.13.1)
|
14
|
+
coderay (~> 1.1)
|
15
|
+
method_source (~> 1.0)
|
16
|
+
pry-byebug (3.9.0)
|
17
|
+
byebug (~> 11.0)
|
18
|
+
pry (~> 0.13.0)
|
19
|
+
rake (13.0.3)
|
20
|
+
rspec (3.10.0)
|
21
|
+
rspec-core (~> 3.10.0)
|
22
|
+
rspec-expectations (~> 3.10.0)
|
23
|
+
rspec-mocks (~> 3.10.0)
|
24
|
+
rspec-core (3.10.1)
|
25
|
+
rspec-support (~> 3.10.0)
|
26
|
+
rspec-expectations (3.10.1)
|
18
27
|
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
-
rspec-support (~> 3.
|
20
|
-
rspec-mocks (3.
|
28
|
+
rspec-support (~> 3.10.0)
|
29
|
+
rspec-mocks (3.10.1)
|
21
30
|
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
-
rspec-support (~> 3.
|
23
|
-
rspec-support (3.
|
31
|
+
rspec-support (~> 3.10.0)
|
32
|
+
rspec-support (3.10.1)
|
24
33
|
|
25
34
|
PLATFORMS
|
26
35
|
ruby
|
@@ -28,8 +37,9 @@ PLATFORMS
|
|
28
37
|
DEPENDENCIES
|
29
38
|
bundler (~> 2.0)
|
30
39
|
injectable!
|
31
|
-
|
40
|
+
pry-byebug
|
41
|
+
rake (~> 13.0)
|
32
42
|
rspec (~> 3.0)
|
33
43
|
|
34
44
|
BUNDLED WITH
|
35
|
-
2.
|
45
|
+
2.2.4
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Injectable
|
2
2
|
|
3
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/a45cc5935a5c16b837ed/maintainability)](https://codeclimate.com/github/rubiconmd/injectable/maintainability)![Ruby](https://github.com/rubiconmd/injectable/workflows/Ruby/badge.svg)
|
4
|
+
|
3
5
|
`Injectable` is an opinionated and declarative [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection) library for ruby.
|
4
6
|
|
5
7
|
It is being used in production (under ruby 2.5.1) in [RubiconMD](https://github.com/rubiconmd) and was extracted from its codebase.
|
@@ -209,8 +211,8 @@ There are several ways of declaring a `#dependency`:
|
|
209
211
|
|
210
212
|
```rb
|
211
213
|
class ReportPdfRenderer
|
212
|
-
include Injectable
|
213
|
-
|
214
|
+
include Injectable
|
215
|
+
|
214
216
|
dependency :some_dependency
|
215
217
|
end
|
216
218
|
```
|
@@ -225,9 +227,9 @@ Notice that this happens **at runtime**, not when defining your class.
|
|
225
227
|
```rb
|
226
228
|
class MyInjectable
|
227
229
|
include Injectable
|
228
|
-
|
230
|
+
|
229
231
|
dependency :client, class: Aws::S3::Client
|
230
|
-
dependency :parser, class: VeryLongClassNameForMyParser
|
232
|
+
dependency :parser, class: VeryLongClassNameForMyParser
|
231
233
|
end
|
232
234
|
```
|
233
235
|
|
@@ -353,6 +355,6 @@ Everyone interacting in the Injectable project’s codebases, issue trackers, ch
|
|
353
355
|
|
354
356
|
- [RubiconMD](https://github.com/rubiconmd) allowed extracting this gem from its codebase and release it as open source.
|
355
357
|
- [Durran Jordan](https://github.com/durran) allowed the usage of the gem name at rubygems.org.
|
356
|
-
- [David Marchante](https://github.com/
|
358
|
+
- [David Marchante](https://github.com/iovis) brainstormed the `initialize`/`call` approach, did all code reviews and provided lots of insightful feedback and suggestions. He also wrote the inline documentation.
|
357
359
|
- [Julio Antequera](https://github.com/jantequera), [Jimmi Carney](https://github.com/ayoformayo) and [Anthony Rocco](https://github.com/amrocco) had the patience to use it and report many bugs. Also most of the features in this gem came up when reviewing their usage of it. Anthony also made the effort of extracting the code from RubiconMD's codebase.
|
358
360
|
- [Rodrigo Álvarez](https://github.com/Papipo) had the idea for the DSL and actually wrote the library.
|
data/injectable.gemspec
CHANGED
@@ -1,28 +1,29 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
3
|
+
require 'injectable/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
6
|
spec.name = 'injectable'
|
8
7
|
spec.version = Injectable::VERSION
|
9
|
-
spec.authors = %w
|
10
|
-
spec.email = %w
|
8
|
+
spec.authors = %w[Papipo iovis jantequera amrocco rewritten]
|
9
|
+
spec.email = %w[dev@rubiconmd.com]
|
11
10
|
|
12
|
-
spec.summary =
|
11
|
+
spec.summary = 'A library to help you build nice service objects with dependency injection.'
|
13
12
|
spec.homepage = 'https://github.com/rubiconmd/injectable'
|
14
|
-
spec.license =
|
13
|
+
spec.license = 'MIT'
|
15
14
|
|
16
15
|
# Specify which files should be added to the gem when it is released.
|
17
16
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
-
spec.files = Dir.chdir(File.expand_path(
|
17
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
19
18
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
19
|
end
|
21
20
|
spec.bindir = 'exe'
|
22
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
22
|
spec.require_paths = ['lib']
|
23
|
+
spec.required_ruby_version = '>= 2.5'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
26
|
-
spec.add_development_dependency '
|
26
|
+
spec.add_development_dependency 'pry-byebug'
|
27
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
27
28
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
29
|
end
|
data/lib/injectable.rb
CHANGED
@@ -5,6 +5,7 @@ require 'injectable/dependencies_proxy'
|
|
5
5
|
require 'injectable/dependency'
|
6
6
|
require 'injectable/instance_methods'
|
7
7
|
require 'injectable/missing_dependencies_exception'
|
8
|
+
require 'injectable/method_already_exists_exception'
|
8
9
|
|
9
10
|
# Convert your class into an injectable service
|
10
11
|
#
|
@@ -97,7 +97,7 @@ module Injectable
|
|
97
97
|
options[:block] = block if block_given?
|
98
98
|
options[:depends_on] = Array(options.fetch(:depends_on, []))
|
99
99
|
options[:name] = name
|
100
|
-
dependencies.add(options)
|
100
|
+
dependencies.add(**options)
|
101
101
|
define_method name do
|
102
102
|
instance_variable_get("@#{name}") || dependencies_proxy.get(name)
|
103
103
|
end
|
@@ -16,13 +16,17 @@ module Injectable
|
|
16
16
|
def wrap_call(the_instance)
|
17
17
|
return the_instance unless call
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
if the_instance.respond_to? :call
|
20
|
+
raise Injectable::MethodAlreadyExistsException
|
21
21
|
end
|
22
|
+
|
23
|
+
the_instance.public_method(call)
|
22
24
|
end
|
23
25
|
|
24
26
|
def build_instance(args, namespace:)
|
25
|
-
|
27
|
+
return klass(namespace: namespace).new(*args) if block.nil?
|
28
|
+
|
29
|
+
block.call(*args)
|
26
30
|
end
|
27
31
|
|
28
32
|
def klass(namespace:)
|
data/lib/injectable/version.rb
CHANGED
metadata
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: injectable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Papipo
|
8
|
-
-
|
8
|
+
- iovis
|
9
9
|
- jantequera
|
10
10
|
- amrocco
|
11
|
-
|
11
|
+
- rewritten
|
12
|
+
autorequire:
|
12
13
|
bindir: exe
|
13
14
|
cert_chain: []
|
14
|
-
date:
|
15
|
+
date: 2021-01-05 00:00:00.000000000 Z
|
15
16
|
dependencies:
|
16
17
|
- !ruby/object:Gem::Dependency
|
17
18
|
name: bundler
|
@@ -27,20 +28,34 @@ dependencies:
|
|
27
28
|
- - "~>"
|
28
29
|
- !ruby/object:Gem::Version
|
29
30
|
version: '2.0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: pry-byebug
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
30
45
|
- !ruby/object:Gem::Dependency
|
31
46
|
name: rake
|
32
47
|
requirement: !ruby/object:Gem::Requirement
|
33
48
|
requirements:
|
34
49
|
- - "~>"
|
35
50
|
- !ruby/object:Gem::Version
|
36
|
-
version: '
|
51
|
+
version: '13.0'
|
37
52
|
type: :development
|
38
53
|
prerelease: false
|
39
54
|
version_requirements: !ruby/object:Gem::Requirement
|
40
55
|
requirements:
|
41
56
|
- - "~>"
|
42
57
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
58
|
+
version: '13.0'
|
44
59
|
- !ruby/object:Gem::Dependency
|
45
60
|
name: rspec
|
46
61
|
requirement: !ruby/object:Gem::Requirement
|
@@ -55,19 +70,18 @@ dependencies:
|
|
55
70
|
- - "~>"
|
56
71
|
- !ruby/object:Gem::Version
|
57
72
|
version: '3.0'
|
58
|
-
description:
|
73
|
+
description:
|
59
74
|
email:
|
60
|
-
-
|
61
|
-
- david.marchante@rubiconmd.com
|
62
|
-
- julio@rubiconmd.com
|
63
|
-
- anthony@rubiconmd.com
|
75
|
+
- dev@rubiconmd.com
|
64
76
|
executables: []
|
65
77
|
extensions: []
|
66
78
|
extra_rdoc_files: []
|
67
79
|
files:
|
80
|
+
- ".github/workflows/ruby.yml"
|
68
81
|
- ".gitignore"
|
69
82
|
- ".rspec"
|
70
83
|
- ".travis.yml"
|
84
|
+
- CHANGELOG.md
|
71
85
|
- CODE_OF_CONDUCT.md
|
72
86
|
- Gemfile
|
73
87
|
- Gemfile.lock
|
@@ -83,13 +97,14 @@ files:
|
|
83
97
|
- lib/injectable/dependencies_proxy.rb
|
84
98
|
- lib/injectable/dependency.rb
|
85
99
|
- lib/injectable/instance_methods.rb
|
100
|
+
- lib/injectable/method_already_exists_exception.rb
|
86
101
|
- lib/injectable/missing_dependencies_exception.rb
|
87
102
|
- lib/injectable/version.rb
|
88
103
|
homepage: https://github.com/rubiconmd/injectable
|
89
104
|
licenses:
|
90
105
|
- MIT
|
91
106
|
metadata: {}
|
92
|
-
post_install_message:
|
107
|
+
post_install_message:
|
93
108
|
rdoc_options: []
|
94
109
|
require_paths:
|
95
110
|
- lib
|
@@ -97,16 +112,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
112
|
requirements:
|
98
113
|
- - ">="
|
99
114
|
- !ruby/object:Gem::Version
|
100
|
-
version: '
|
115
|
+
version: '2.5'
|
101
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
117
|
requirements:
|
103
118
|
- - ">="
|
104
119
|
- !ruby/object:Gem::Version
|
105
120
|
version: '0'
|
106
121
|
requirements: []
|
107
|
-
|
108
|
-
|
109
|
-
signing_key:
|
122
|
+
rubygems_version: 3.1.2
|
123
|
+
signing_key:
|
110
124
|
specification_version: 4
|
111
125
|
summary: A library to help you build nice service objects with dependency injection.
|
112
126
|
test_files: []
|