dry-auto_inject 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +11 -14
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -0
- data/README.md +3 -30
- data/lib/dry/auto_inject/strategies/kwargs.rb +11 -11
- data/lib/dry/auto_inject/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5d25d77aea481c1dfd5c35eb30eaca7d921b1a7
|
4
|
+
data.tar.gz: a9512d492a6805f94b33784683f13a64ec6fe69d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a270fe530357ac14278071e5d76dca6a2dd4e07865817d0e9f2e3524af8138a250d403261615737f8a084803bcacd38ec7b8a765a5af9f2034b515ca71e093ac
|
7
|
+
data.tar.gz: 4dcfbdeb49aeccb0109b414d4e0d18e7733bbb2ff5b70b4be9ec4582c4e6aacad9c5755d368a14ad04c02de79fe87895450358f4cca55dcc2012d5e07581feda
|
data/.travis.yml
CHANGED
@@ -1,24 +1,21 @@
|
|
1
1
|
language: ruby
|
2
|
-
|
2
|
+
dist: trusty
|
3
|
+
sudo: required
|
3
4
|
cache: bundler
|
4
|
-
bundler_args: --without
|
5
|
+
bundler_args: --without tools
|
5
6
|
script:
|
6
|
-
- bundle exec rake
|
7
|
+
- bundle exec rake
|
8
|
+
after_success:
|
9
|
+
- '[ -d coverage ] && bundle exec codeclimate-test-reporter'
|
7
10
|
rvm:
|
8
|
-
- 2.1
|
9
|
-
- 2.2
|
10
|
-
- 2.3.
|
11
|
-
-
|
12
|
-
-
|
13
|
-
- jruby-head
|
11
|
+
- 2.1.10
|
12
|
+
- 2.2.7
|
13
|
+
- 2.3.4
|
14
|
+
- 2.4.1
|
15
|
+
- jruby-9.1.10.0
|
14
16
|
env:
|
15
17
|
global:
|
16
18
|
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
17
|
-
matrix:
|
18
|
-
allow_failures:
|
19
|
-
- rvm: rbx
|
20
|
-
- rvm: ruby-head
|
21
|
-
- rvm: jruby-head
|
22
19
|
addons:
|
23
20
|
code_climate:
|
24
21
|
repo_token: 029b5aa100b82b6710e285597b7eabe760357b5dd1f626514371356055378d8c
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
[![API Documentation Coverage](http://inch-ci.org/github/dry-rb/dry-auto_inject.svg)][inch]
|
15
15
|
![No monkey-patches](https://img.shields.io/badge/monkey--patches-0-brightgreen.svg)
|
16
16
|
|
17
|
-
A simple
|
17
|
+
A simple extension which allows you to automatically inject dependencies to your
|
18
18
|
object constructors from a configured container.
|
19
19
|
|
20
20
|
It does 3 things:
|
@@ -42,36 +42,9 @@ Or install it yourself as:
|
|
42
42
|
$ gem install dry-auto_inject
|
43
43
|
```
|
44
44
|
|
45
|
-
##
|
45
|
+
## Links
|
46
46
|
|
47
|
-
|
48
|
-
we're going to use `dry-container`:
|
49
|
-
|
50
|
-
```ruby
|
51
|
-
# set up your container
|
52
|
-
my_container = Dry::Container.new
|
53
|
-
|
54
|
-
my_container.register(:data_store, -> { DataStore.new })
|
55
|
-
my_container.register(:user_repository, -> { container[:data_store][:users] })
|
56
|
-
my_container.register(:persist_user, -> { PersistUser.new })
|
57
|
-
|
58
|
-
# set up your auto-injection function
|
59
|
-
AutoInject = Dry::AutoInject(my_container)
|
60
|
-
|
61
|
-
# then simply include it in your class providing which dependencies should be
|
62
|
-
# injected automatically from the configured container
|
63
|
-
class PersistUser
|
64
|
-
include AutoInject[:user_repository]
|
65
|
-
|
66
|
-
def call(user)
|
67
|
-
user_repository << user
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
persist_user = my_container[:persist_user]
|
72
|
-
|
73
|
-
persist_user.call(name: 'Jane')
|
74
|
-
```
|
47
|
+
* [Documentation](http://dry-rb.org/gems/dry-auto_inject/)
|
75
48
|
|
76
49
|
## Development
|
77
50
|
|
@@ -9,12 +9,12 @@ module Dry
|
|
9
9
|
|
10
10
|
def define_new
|
11
11
|
class_mod.class_exec(container, dependency_map) do |container, dependency_map|
|
12
|
-
define_method :new do
|
12
|
+
define_method :new do |*args, **kwargs|
|
13
13
|
deps = dependency_map.to_h.each_with_object({}) { |(name, identifier), obj|
|
14
|
-
obj[name] =
|
15
|
-
}.merge(
|
14
|
+
obj[name] = kwargs[name] || container[identifier]
|
15
|
+
}.merge(kwargs)
|
16
16
|
|
17
|
-
super(**deps)
|
17
|
+
super(*args, **deps)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -45,21 +45,21 @@ module Dry
|
|
45
45
|
|
46
46
|
def define_initialize_with_splat(super_method)
|
47
47
|
super_kwarg_names = super_method.parameters.select { |type, _| [:key, :keyreq].include?(type) }.map(&:last)
|
48
|
-
|
48
|
+
super_kw_params = super_kwarg_names.map { |name| "#{name}: kwargs[:#{name}]" }.join(', ')
|
49
49
|
|
50
50
|
# Pass through any non-dependency args if the super method accepts `**args`
|
51
51
|
if super_method.parameters.any? { |type, _| type == :keyrest }
|
52
|
-
if
|
53
|
-
|
52
|
+
if super_kw_params.empty?
|
53
|
+
super_kw_params = '**kwargs'
|
54
54
|
else
|
55
|
-
|
55
|
+
super_kw_params += ', **kwargs'
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
instance_mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
60
|
-
def initialize(**
|
61
|
-
super(#{
|
62
|
-
#{dependency_map.names.map { |name| "@#{name} =
|
60
|
+
def initialize(*args, **kwargs)
|
61
|
+
super(*args, #{super_kw_params})
|
62
|
+
#{dependency_map.names.map { |name| "@#{name} = kwargs[:#{name}]" }.join("\n")}
|
63
63
|
end
|
64
64
|
RUBY
|
65
65
|
self
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-auto_inject
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-container
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.6.11
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: Container-agnostic automatic constructor injection
|