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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fd381da253e837a08d3fdce402293a69d6a3c639
4
- data.tar.gz: e12e0499bb82f1206b454e01a56cacfb97d34aff
2
+ SHA256:
3
+ metadata.gz: 4c33a7e6329e0be38838c859c3c5f3ffb26711eaf760ec2d40205f4a94d42ade
4
+ data.tar.gz: 8c08498f9f7ee47a901ebe60f9bf59a3922cd243c161d1c0c75e14b03a4117bc
5
5
  SHA512:
6
- metadata.gz: 18a59ab5c45f4becab2bb9a9c29fc13f6a712929306be4ecb3e64ba5c03be8a20a3a0a3c26a579f037998877e4045d99c957b0664fba481f698b4b28ffba3d69
7
- data.tar.gz: 35fed3c5f7ee5a829e2eb96c06f33512b1dcaaaf40882a937a7dfa7e619f0d45b1ce60b7dd3a38f4d36c2b833cb33212a37d330ece79784dc071188711cf6fa2
6
+ metadata.gz: 71ef77c12ecc339991afa3d90b3786778ea9575ed33a126281eedb337fa49cdb2462c1c6468fc131b0c102be113a6f88f2bd375497cd1fc2009eda6f96531b3d
7
+ data.tar.gz: 9c957dac63e4fc6cbcbb82e5e0318ed355f65d231c5e74aaa8e09b85d2d3ae7a8aa48a663b9d19ff4ec7efc4f246dc314934233a3d414b23904b5abb2cb12cbd
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Marcelo Jacobus
3
+ Copyright (c) 2015-2017 Marcelo Jacobus
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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(UserRepository) do |dependency_manager|
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(UserRepository)
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::SharedServiceFactory
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
- fail 'create_service must be implemented'
18
+ raise 'create_service must be implemented'
11
19
  end
12
20
 
13
21
  def dependency_key
14
- fail 'dependency_key must be implemented'
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 attach_to(dependency_manager)
4
- dependency_manager.share(dependency_key) do |di|
5
- create_service(di)
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
@@ -1,3 +1,3 @@
1
1
  module Nurse
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
3
3
  end
@@ -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 dependnecy injection'
13
- spec.description = 'Nurse, for your dependnecy injection. Dependency injection management'
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.0.0
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: 2017-02-27 00:00:00.000000000 Z
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 dependnecy injection. Dependency injection management
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.5.1
155
+ rubygems_version: 2.7.6
156
156
  signing_key:
157
157
  specification_version: 4
158
- summary: Nurse, for your dependnecy injection
158
+ summary: Nurse, for your dependency injection
159
159
  test_files: []