nurse-rb 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE.txt +1 -1
- data/README.md +13 -16
- data/lib/nurse/service_factory.rb +34 -2
- data/lib/nurse/shared_service_factory.rb +9 -3
- data/lib/nurse/version.rb +1 -1
- data/nurse-rb.gemspec +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4c33a7e6329e0be38838c859c3c5f3ffb26711eaf760ec2d40205f4a94d42ade
|
4
|
+
data.tar.gz: 8c08498f9f7ee47a901ebe60f9bf59a3922cd243c161d1c0c75e14b03a4117bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71ef77c12ecc339991afa3d90b3786778ea9575ed33a126281eedb337fa49cdb2462c1c6468fc131b0c102be113a6f88f2bd375497cd1fc2009eda6f96531b3d
|
7
|
+
data.tar.gz: 9c957dac63e4fc6cbcbb82e5e0318ed355f65d231c5e74aaa8e09b85d2d3ae7a8aa48a663b9d19ff4ec7efc4f246dc314934233a3d414b23904b5abb2cb12cbd
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,7 @@ Nurse, for your dependency injection
|
|
5
5
|
Code quality
|
6
6
|
|
7
7
|
[![Build Status](https://travis-ci.org/mjacobus/nurse-rb.svg)](https://travis-ci.org/mjacobus/nurse-rb)
|
8
|
-
[![Coverage Status](https://coveralls.io/repos/github/mjacobus/nurse/badge.svg?branch=master)](https://coveralls.io/github/mjacobus/nurse?branch=master)
|
8
|
+
[![Coverage Status](https://coveralls.io/repos/github/mjacobus/nurse-rb/badge.svg?branch=master)](https://coveralls.io/github/mjacobus/nurse-rb?branch=master)
|
9
9
|
[![Code Coverage](https://scrutinizer-ci.com/g/mjacobus/nurse-rb/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/mjacobus/nurse-rb/?branch=master)
|
10
10
|
[![Code Climate](https://codeclimate.com/github/mjacobus/nurse-rb/badges/gpa.svg)](https://codeclimate.com/github/mjacobus/nurse-rb)
|
11
11
|
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mjacobus/nurse-rb/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mjacobus/nurse-rb/?branch=master)
|
@@ -20,7 +20,7 @@ Package information
|
|
20
20
|
Add this line to your application's Gemfile:
|
21
21
|
|
22
22
|
```ruby
|
23
|
-
gem 'nurse'
|
23
|
+
gem 'nurse-rb'
|
24
24
|
```
|
25
25
|
|
26
26
|
And then execute:
|
@@ -29,7 +29,7 @@ And then execute:
|
|
29
29
|
|
30
30
|
Or install it yourself as:
|
31
31
|
|
32
|
-
$ gem install nurse
|
32
|
+
$ gem install nurse-rb
|
33
33
|
|
34
34
|
## Usage
|
35
35
|
|
@@ -42,7 +42,7 @@ dependency_manager.share(:connection) do |dependency_manager|
|
|
42
42
|
MyConnection.new("mysql://root@localhost/my_db")
|
43
43
|
end
|
44
44
|
|
45
|
-
dependency_manager.share(
|
45
|
+
dependency_manager.share(:user_repository) do |dependency_manager|
|
46
46
|
connection = dependency_manager.get(:connection)
|
47
47
|
UserRepository.new(connection)
|
48
48
|
end
|
@@ -65,38 +65,35 @@ class UsersController < SomeBaseController
|
|
65
65
|
private
|
66
66
|
|
67
67
|
def repository
|
68
|
-
dependency_manager.get(
|
68
|
+
dependency_manager.get(:user_repository)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
```
|
72
72
|
|
73
|
+
### Using factories
|
74
|
+
|
73
75
|
```ruby
|
74
|
-
class DatabaseConnectionFactory < Nurse::
|
76
|
+
class DatabaseConnectionFactory < Nurse::ServiceFactory
|
77
|
+
share true
|
78
|
+
key :db_connection
|
79
|
+
|
75
80
|
def create_service(dependencies)
|
76
81
|
DatabaseConnection.new(dependencies.get(:db_config))
|
77
82
|
end
|
78
|
-
|
79
|
-
def dependency_key
|
80
|
-
:db_connection
|
81
|
-
end
|
82
83
|
end
|
83
84
|
|
84
85
|
class UserRepositoryFactory < Nurse::ServiceFactory
|
86
|
+
key :user_repository
|
87
|
+
|
85
88
|
def create_service(dependencies)
|
86
89
|
UserRepository.new(dependencies.get(:db_connection))
|
87
90
|
end
|
88
|
-
|
89
|
-
def dependency_key
|
90
|
-
:user_repository
|
91
|
-
end
|
92
91
|
end
|
93
92
|
|
94
93
|
dependency_manager.add_factory(DatabaseConnectionFactory.new)
|
95
94
|
dependency_manager.add_factory(UserRepositoryFactory.new)
|
96
95
|
```
|
97
96
|
|
98
|
-
### Using factories
|
99
|
-
|
100
97
|
## Development
|
101
98
|
|
102
99
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -1,17 +1,49 @@
|
|
1
1
|
module Nurse
|
2
2
|
class ServiceFactory
|
3
3
|
def attach_to(dependency_manager)
|
4
|
+
if shared?
|
5
|
+
dependency_manager.share(dependency_key) do |di|
|
6
|
+
create_service(di)
|
7
|
+
end
|
8
|
+
|
9
|
+
return
|
10
|
+
end
|
11
|
+
|
4
12
|
dependency_manager.set(dependency_key) do |di|
|
5
13
|
create_service(di)
|
6
14
|
end
|
7
15
|
end
|
8
16
|
|
9
17
|
def create_service(_dependency_manager)
|
10
|
-
|
18
|
+
raise 'create_service must be implemented'
|
11
19
|
end
|
12
20
|
|
13
21
|
def dependency_key
|
14
|
-
|
22
|
+
raise 'dependency_key must be implemented'
|
23
|
+
end
|
24
|
+
|
25
|
+
def shared?
|
26
|
+
false
|
27
|
+
end
|
28
|
+
|
29
|
+
class << self
|
30
|
+
private
|
31
|
+
|
32
|
+
def share(boolean)
|
33
|
+
instance_eval do
|
34
|
+
define_method :shared? do
|
35
|
+
boolean
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def key(dependency_key)
|
41
|
+
instance_eval do
|
42
|
+
define_method :dependency_key do
|
43
|
+
dependency_key
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
15
47
|
end
|
16
48
|
end
|
17
49
|
end
|
@@ -1,8 +1,14 @@
|
|
1
1
|
module Nurse
|
2
2
|
class SharedServiceFactory < ServiceFactory
|
3
|
-
def
|
4
|
-
|
5
|
-
|
3
|
+
def shared?
|
4
|
+
true
|
5
|
+
end
|
6
|
+
|
7
|
+
class << self
|
8
|
+
private
|
9
|
+
|
10
|
+
def share(_shared)
|
11
|
+
raise 'You cannot change the shared state of a shared service factory. Extend Nurse::ServiceFactory instead'
|
6
12
|
end
|
7
13
|
end
|
8
14
|
end
|
data/lib/nurse/version.rb
CHANGED
data/nurse-rb.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ['Marcelo Jacobus']
|
10
10
|
spec.email = ['marcelo.jacobus@gmail.com']
|
11
11
|
|
12
|
-
spec.summary = 'Nurse, for your
|
13
|
-
spec.description = 'Nurse, for your
|
12
|
+
spec.summary = 'Nurse, for your dependency injection'
|
13
|
+
spec.description = 'Nurse, for your dependency injection. Dependency injection container'
|
14
14
|
spec.homepage = 'https://github.com/mjacobus/nurse-rb'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nurse-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcelo Jacobus
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
-
description: Nurse, for your
|
111
|
+
description: Nurse, for your dependency injection. Dependency injection container
|
112
112
|
email:
|
113
113
|
- marcelo.jacobus@gmail.com
|
114
114
|
executables: []
|
@@ -152,8 +152,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
version: '0'
|
153
153
|
requirements: []
|
154
154
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.7.6
|
156
156
|
signing_key:
|
157
157
|
specification_version: 4
|
158
|
-
summary: Nurse, for your
|
158
|
+
summary: Nurse, for your dependency injection
|
159
159
|
test_files: []
|