ruby-ioc 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/ioc.rb +9 -0
- data/lib/ioc/container.rb +50 -0
- data/lib/ioc/core_ext/all.rb +3 -0
- data/lib/ioc/core_ext/object.rb +7 -0
- data/lib/ioc/dependency.rb +18 -0
- data/lib/ioc/helper.rb +12 -0
- data/lib/ioc/version.rb +5 -0
- data/lib/ruby-ioc.rb +3 -0
- data/ruby-ioc.gemspec +26 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3430ca77cb277c9e94b6309fe6c6148dcff80adef8575a07801d5ff07d6cdfa8
|
4
|
+
data.tar.gz: '0943e6c697b7dfed4dfcf0d41e59b505eb2ba86221f56930de5c7714057ae56b'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cfb59c59c11e5b40cf1ea4370969c955af3a0f7db90a793ba2bf83a8789149d7484611ee24c93c22a83b9f89244f1996a3fa8b67ab03367387450f15461d158a
|
7
|
+
data.tar.gz: f25d1f4259f9ba975017bbba4c68b18469a778768d69a82a534e10d186af750458f12db64da6f02d1a2af1888952be7737e65ee48ae234423d7b78ae088d15b0
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ruby-ioc (0.0.2)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.11.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 1.17)
|
17
|
+
minitest (~> 5.0)
|
18
|
+
rake (~> 10.0)
|
19
|
+
ruby-ioc!
|
20
|
+
|
21
|
+
BUNDLED WITH
|
22
|
+
1.17.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Alisson Santos
|
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
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# IoC
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
```ruby
|
5
|
+
gem 'ruby-ioc'
|
6
|
+
```
|
7
|
+
And then execute:
|
8
|
+
```
|
9
|
+
$ bundle install
|
10
|
+
```
|
11
|
+
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
```
|
15
|
+
$ gem install ruby-ioc
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
|
22
|
+
IoC::Container.init do |container|
|
23
|
+
# singleton value
|
24
|
+
container.register(:user_repository, UserRepository)
|
25
|
+
|
26
|
+
# new instance value
|
27
|
+
container.register(:checkout_service) { CheckoutService.new }
|
28
|
+
end
|
29
|
+
|
30
|
+
class CheckoutService
|
31
|
+
inject :user_repository
|
32
|
+
|
33
|
+
def call(checkout)
|
34
|
+
# valid checkout
|
35
|
+
# ...
|
36
|
+
# ...
|
37
|
+
checkout_repository.save(checkout)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/alissonbrunosa/ruby-ioc.
|
44
|
+
|
45
|
+
## License
|
46
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ioc"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/ioc.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "singleton"
|
4
|
+
require "ioc/dependency"
|
5
|
+
|
6
|
+
module IoC
|
7
|
+
class Container
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@depedencies = Hash.new
|
12
|
+
@mutex = Mutex.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.init
|
16
|
+
yield(instance)
|
17
|
+
end
|
18
|
+
|
19
|
+
def register(name, value = nil, &block)
|
20
|
+
raise ArgumentError, "WTF dude?" unless name && (value || block)
|
21
|
+
|
22
|
+
synchronized do
|
23
|
+
dependency = if block_given?
|
24
|
+
Dependency.new(block)
|
25
|
+
else
|
26
|
+
Dependency.new(value, singleton: true)
|
27
|
+
end
|
28
|
+
|
29
|
+
depedencies[name] = dependency
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def retrieve(name)
|
34
|
+
synchronized do
|
35
|
+
dependency = depedencies.fetch(name)
|
36
|
+
dependency.call
|
37
|
+
end
|
38
|
+
rescue KeyError
|
39
|
+
raise DependencyNotFound, "Dependency not found"
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
attr_reader :depedencies, :mutex
|
45
|
+
|
46
|
+
def synchronized(&block)
|
47
|
+
mutex.synchronize(&block)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IoC
|
4
|
+
class Dependency
|
5
|
+
def initialize(value, singleton: false)
|
6
|
+
@value = value
|
7
|
+
@singleton = singleton
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
singleton ? value : value.call
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
attr_reader :value, :singleton
|
17
|
+
end
|
18
|
+
end
|
data/lib/ioc/helper.rb
ADDED
data/lib/ioc/version.rb
ADDED
data/lib/ruby-ioc.rb
ADDED
data/ruby-ioc.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "ioc/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruby-ioc"
|
8
|
+
spec.version = IoC::VERSION
|
9
|
+
spec.authors = ["Alisson Santos"]
|
10
|
+
spec.email = ["alissonbruno.sa@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Simple IoC gem}
|
13
|
+
spec.homepage = "https://github.com/alissonbrunosa/ruby-ioc"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-ioc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alisson Santos
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- alissonbruno.sa@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- lib/ioc.rb
|
72
|
+
- lib/ioc/container.rb
|
73
|
+
- lib/ioc/core_ext/all.rb
|
74
|
+
- lib/ioc/core_ext/object.rb
|
75
|
+
- lib/ioc/dependency.rb
|
76
|
+
- lib/ioc/helper.rb
|
77
|
+
- lib/ioc/version.rb
|
78
|
+
- lib/ruby-ioc.rb
|
79
|
+
- ruby-ioc.gemspec
|
80
|
+
homepage: https://github.com/alissonbrunosa/ruby-ioc
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubygems_version: 3.0.4
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Simple IoC gem
|
103
|
+
test_files: []
|