sinject 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sinject.rb +0 -1
- data/lib/sinject/container.rb +2 -3
- data/lib/sinject/exceptions.rb +1 -1
- metadata +6 -20
- data/.DS_Store +0 -0
- data/.gitignore +0 -10
- data/.rspec +0 -3
- data/CODE_OF_CONDUCT.md +0 -49
- data/Gemfile +0 -3
- data/LICENSE.txt +0 -21
- data/README.md +0 -137
- data/Rakefile +0 -2
- data/lib/sinject/version.rb +0 -3
- data/sinject.gemspec +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ff53f60728f9e82cae343665133a1afb5fd25a4
|
4
|
+
data.tar.gz: 484be6ecc45857889ad818ac5f9cb5d4d5af86cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13c4fca49e08c1da9e8936b4890c087377bfc08fdf0e234b122fdd5279e5d428451c2763e04ceecbdd9a4bff290e58057fdd3db1e13e4a7a5f45b892b9d290c9
|
7
|
+
data.tar.gz: 670cda2067966140a1f3e1577fc24480e7b38a38aaa74366937a06de8731e997d13558ec93bceb17b45acb9c54395f803d6694bd3eb77a2f7c94917c49b0bcc7
|
data/lib/sinject.rb
CHANGED
data/lib/sinject/container.rb
CHANGED
@@ -43,7 +43,7 @@ module Sinject
|
|
43
43
|
raise Sinject::DependencyRegistrationKeyNotSpecifiedException.new
|
44
44
|
end
|
45
45
|
|
46
|
-
if(!options.has_key?(:
|
46
|
+
if(!options.has_key?(:class))
|
47
47
|
raise Sinject::DependencyRegistrationClassNotSpecifiedException.new
|
48
48
|
end
|
49
49
|
|
@@ -117,7 +117,7 @@ module Sinject
|
|
117
117
|
Sinject::DependencyGroup.descendants.each do |g|
|
118
118
|
group = g.new
|
119
119
|
if group.is_valid?
|
120
|
-
group.register(
|
120
|
+
group.register(self)
|
121
121
|
end
|
122
122
|
end
|
123
123
|
end
|
@@ -155,7 +155,6 @@ module Sinject
|
|
155
155
|
end
|
156
156
|
|
157
157
|
def create_instance(item)
|
158
|
-
instance = nil
|
159
158
|
|
160
159
|
#check if a custom initializer block has been specified
|
161
160
|
if item.initialize_block != nil
|
data/lib/sinject/exceptions.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinject
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Sage One
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -54,23 +54,11 @@ dependencies:
|
|
54
54
|
version: '3.0'
|
55
55
|
description: A simple dependency injection framework.
|
56
56
|
email:
|
57
|
-
-
|
57
|
+
- vaughan.britton@sage.com
|
58
58
|
executables: []
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- ".DS_Store"
|
63
|
-
- ".gitignore"
|
64
|
-
- ".idea/.rakeTasks"
|
65
|
-
- ".idea/misc.xml"
|
66
|
-
- ".idea/modules.xml"
|
67
|
-
- ".idea/vcs.xml"
|
68
|
-
- ".rspec"
|
69
|
-
- CODE_OF_CONDUCT.md
|
70
|
-
- Gemfile
|
71
|
-
- LICENSE.txt
|
72
|
-
- README.md
|
73
|
-
- Rakefile
|
74
62
|
- bin/console
|
75
63
|
- bin/setup
|
76
64
|
- lib/sinject.rb
|
@@ -79,9 +67,7 @@ files:
|
|
79
67
|
- lib/sinject/container_item.rb
|
80
68
|
- lib/sinject/dependency_group.rb
|
81
69
|
- lib/sinject/exceptions.rb
|
82
|
-
|
83
|
-
- sinject.gemspec
|
84
|
-
homepage: https://github.com/vaughanbrittonsage/sinject
|
70
|
+
homepage: https://github.com/sage/sinject
|
85
71
|
licenses:
|
86
72
|
- MIT
|
87
73
|
metadata: {}
|
@@ -101,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
87
|
version: '0'
|
102
88
|
requirements: []
|
103
89
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.5
|
90
|
+
rubygems_version: 2.4.5
|
105
91
|
signing_key:
|
106
92
|
specification_version: 4
|
107
93
|
summary: Simple Dependency Injection.
|
data/.DS_Store
DELETED
Binary file
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
# Contributor Code of Conduct
|
2
|
-
|
3
|
-
As contributors and maintainers of this project, and in the interest of
|
4
|
-
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
-
contribute through reporting issues, posting feature requests, updating
|
6
|
-
documentation, submitting pull requests or patches, and other activities.
|
7
|
-
|
8
|
-
We are committed to making participation in this project a harassment-free
|
9
|
-
experience for everyone, regardless of level of experience, gender, gender
|
10
|
-
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
-
body size, race, ethnicity, age, religion, or nationality.
|
12
|
-
|
13
|
-
Examples of unacceptable behavior by participants include:
|
14
|
-
|
15
|
-
* The use of sexualized language or imagery
|
16
|
-
* Personal attacks
|
17
|
-
* Trolling or insulting/derogatory comments
|
18
|
-
* Public or private harassment
|
19
|
-
* Publishing other's private information, such as physical or electronic
|
20
|
-
addresses, without explicit permission
|
21
|
-
* Other unethical or unprofessional conduct
|
22
|
-
|
23
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
-
threatening, offensive, or harmful.
|
28
|
-
|
29
|
-
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
-
fairly and consistently applying these principles to every aspect of managing
|
31
|
-
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
-
Conduct may be permanently removed from the project team.
|
33
|
-
|
34
|
-
This code of conduct applies both within project spaces and in public spaces
|
35
|
-
when an individual is representing the project or its community.
|
36
|
-
|
37
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
-
reported by contacting a project maintainer at vaughan.britton@sage.com. All
|
39
|
-
complaints will be reviewed and investigated and will result in a response that
|
40
|
-
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
-
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
-
incident.
|
43
|
-
|
44
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
-
version 1.3.0, available at
|
46
|
-
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
-
|
48
|
-
[homepage]: http://contributor-covenant.org
|
49
|
-
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2016 vaughanbrittonsage
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,137 +0,0 @@
|
|
1
|
-
|
2
|
-
# Sinject
|
3
|
-
|
4
|
-
Welcome to Sinject! a simple dependency injection framework for ruby.
|
5
|
-
|
6
|
-
[Note: The update to v 1.0.0 contains breaking changes. All code has now been moved into the module 'Sinject::*' and the register method of the container has been modified to take an options hash as apposed to requiring multiple method arguments.]
|
7
|
-
|
8
|
-
## Installation
|
9
|
-
|
10
|
-
Add this line to your application's Gemfile:
|
11
|
-
|
12
|
-
```ruby
|
13
|
-
gem 'sinject'
|
14
|
-
```
|
15
|
-
|
16
|
-
And then execute:
|
17
|
-
|
18
|
-
$ bundle
|
19
|
-
|
20
|
-
Or install it yourself as:
|
21
|
-
|
22
|
-
$ gem install sinject
|
23
|
-
|
24
|
-
## Usage
|
25
|
-
|
26
|
-
**Registering dependencies**
|
27
|
-
|
28
|
-
Dependency objects need to be registered with the container before use, to do so you need to configure the Sinject::Container. [Note: This should be done after all code files have been required as the last step before your application starts.]
|
29
|
-
|
30
|
-
#initialize the container
|
31
|
-
container = Sinject::Container.new
|
32
|
-
|
33
|
-
#register your dependencies
|
34
|
-
container.register({ :key => :cache_store, :class => RedisCacheStore, :singleton => true })
|
35
|
-
container.register({ :key => :country_repository, :class => MySqlCountryRepository, :singleton => false })
|
36
|
-
|
37
|
-
Dependencies can be registered with the container in 2 modes:
|
38
|
-
|
39
|
-
- **Single instance:** This mode ensures that only 1 instance is created for the registered dependency and that all requests to the container for that dependency return the same instance.
|
40
|
-
- **Multi instance:** This mode ensures that a new instance of the registered dependency is returned for each request received by the container.
|
41
|
-
|
42
|
-
The registration mode can be set by specifying **true** or **false** to the *':singleton'* argument of the containers register method.
|
43
|
-
|
44
|
-
Dependencies that require custom initialization can be registered with an initialization block to handle the creation of the dependency, this allows you more control over how the dependency is created if required:
|
45
|
-
|
46
|
-
container.register({ :key => :cache_store, :class => RedisCacheStore, :singleton => true }) do
|
47
|
-
instance = RedisCacheStore.new
|
48
|
-
instance.host = 'http://localhost'
|
49
|
-
instance.port = '6369'
|
50
|
-
instance
|
51
|
-
end
|
52
|
-
|
53
|
-
Dependencies with a custom initialization block must return an object of the registered dependency class type, if an unexpected instance is returned then Sinject will raise a `Sinject::DependencyInitializeException`.
|
54
|
-
|
55
|
-
**Assigning dependencies**
|
56
|
-
|
57
|
-
To assign a dependency to an object you need to add the dependency attribute to the class and specify the symbol key that was used to register the dependency with the SinjectContainer:
|
58
|
-
|
59
|
-
class MySqlCountryRepository
|
60
|
-
|
61
|
-
dependency :cache_store
|
62
|
-
|
63
|
-
.....
|
64
|
-
end
|
65
|
-
|
66
|
-
class CountryController < ActionController::Base
|
67
|
-
|
68
|
-
dependency :country_repository
|
69
|
-
|
70
|
-
.....
|
71
|
-
end
|
72
|
-
|
73
|
-
Sinject will then inject the registered dependency to that object and it will be accessible via the dependency key:
|
74
|
-
|
75
|
-
country_controller.country_repository.cache_store
|
76
|
-
|
77
|
-
|
78
|
-
**Dependency Contracts**
|
79
|
-
|
80
|
-
Dependency contracts can be defined to validate registered dependencies are valid for the task they are being registered for. *(If you are familiar with other type based languages then you can think of this as a kind of Interface)*
|
81
|
-
|
82
|
-
To create a dependency contract you need to create a new class with empty methods for each of the methods that the dependency needs to respond to in order to fulfill it's role:
|
83
|
-
|
84
|
-
class LoggerContract
|
85
|
-
def write(message)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
Then when registering a dependency for the role the contract is written for, you can assign the contract:
|
90
|
-
|
91
|
-
#register the dependency
|
92
|
-
container.register({ :key => :logger, :class => FileLogger, :singleton => false, :contract => LoggerContract })
|
93
|
-
|
94
|
-
Sinject will then validate that the registered dependency meets the requirements specified within the contract. If a dependency does not meet the contract requirements then 1 of the following exceptions will be raised:
|
95
|
-
|
96
|
-
- `Sinject::DependencyContractMissingMethodsException` is raised when 1 or more methods from the contract could not be found on the dependency.
|
97
|
-
- `Sinject::DependencyContractInvalidParametersException` is raised when the parameters of a contract method do not match the parameters found on a dependency method.
|
98
|
-
|
99
|
-
**Dependency Groups**
|
100
|
-
|
101
|
-
Dependency registration groups can be created to allow groups of dependencies to be set without the need for manual registration *(e.g. to include with a gem for auto registration)*, or to allow different dependency groups to be loaded in different circumstances *(e.g. per environment)*.
|
102
|
-
|
103
|
-
To create a dependency group, create a class that inherits from the `Sinject::DependencyGroup` base class and implement the `register` & `is_valid?` methods.
|
104
|
-
|
105
|
-
For example:
|
106
|
-
|
107
|
-
#create a development only dependency group
|
108
|
-
class DevelopmentDependencies < Sinject::DependencyGroup
|
109
|
-
def register(container)
|
110
|
-
container.register(:cache_store, LocalCacheStore, true)
|
111
|
-
container.register(:logger, TerminalLogger, true)
|
112
|
-
end
|
113
|
-
|
114
|
-
def is_valid?
|
115
|
-
Rails.env.development?
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
To load valid dependency groups the following method needs to be called from the container:
|
120
|
-
|
121
|
-
container.load_groups
|
122
|
-
|
123
|
-
|
124
|
-
## Development
|
125
|
-
|
126
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
127
|
-
|
128
|
-
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).
|
129
|
-
|
130
|
-
## Contributing
|
131
|
-
|
132
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/vaughanbrittonsage/sinject. 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.
|
133
|
-
|
134
|
-
|
135
|
-
## License
|
136
|
-
|
137
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
DELETED
data/lib/sinject/version.rb
DELETED
data/sinject.gemspec
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'sinject/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "sinject"
|
8
|
-
spec.version = Sinject::VERSION
|
9
|
-
spec.authors = ["vaughan britton"]
|
10
|
-
spec.email = ["vaughanbritton@gmail.com"]
|
11
|
-
|
12
|
-
spec.summary = "Simple Dependency Injection."
|
13
|
-
spec.description = "A simple dependency injection framework."
|
14
|
-
spec.homepage = "https://github.com/vaughanbrittonsage/sinject"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir = "exe"
|
19
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = ["lib"]
|
21
|
-
|
22
|
-
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
-
end
|