strudel 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +124 -0
- data/Rakefile +11 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/bin/yard +16 -0
- data/bin/yardoc +16 -0
- data/bin/yri +16 -0
- data/lib/strudel.rb +162 -0
- data/strudel.gemspec +26 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YjE1YjU5NGQwMGM2ZDVhN2Y4NzRjNWUxODJlYWM1NDdlNmIxNGM1Yg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjViNzIwNjY2ZmEzMWI3ZGIxMTEyZDFkZDJlYTdmYTVhYjI3YzZlYQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODI4ZjFmMDVhMzQwNTc1NjE0OGM2ZTMwMjE0NGIxNjE5NmVjZmUwNzk2MGUz
|
10
|
+
YzljMzVhMjA5NmI1NDA2M2M2YzdhZmFkNTAyMjA2MTdmMTI0ZmE0YTFkYzcx
|
11
|
+
YzY0ZGY4OTU2NTY1YTFkZWQ2OGJiMmViOTE4Y2JhNTAxYjdiNDM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTZiNjhlYTY0ZmMyZGFhNGU1NjQ4Mjc5YzgyYzM4YWJlNTI2OTVkM2M2ZmUz
|
14
|
+
N2MwY2Y5NWEyOTEyNmRmMjIwNWUwNDFjMjFiZjFmNWNhZTU3YTdlYmQzYjMy
|
15
|
+
MjlmYWI2MTZmZTE5M2QzZDQxMzgyNDU2YTc5MDFlYTEzYjQ5Y2I=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.0.0
|
4
|
+
- 2.2.2
|
5
|
+
deploy:
|
6
|
+
provider: rubygems
|
7
|
+
api_key:
|
8
|
+
secure: f1rTqFzMHA1DueBSv7YzFOHy6JxUuSwflvSL6TXG5v5bWs0c6KWi1LhY43pYnpoY3ZyDtFAGgKyvQvvFCvrTB0jQx2lFo2fbXD7LoT1ThX3GLYPvGO79ycUzmXlhNFOGPZo1V3iGb5xAo8ZOVSKNesFWivy81b9SEsL4alv1QUfd2iDs4GzGJMwMIQy758PY21vQhGFfKDXld4ei9cK3hCS4999MluWtjt624FTs9oKoMfzZHfBpMa4ml6oogM1CR3tY8OzjXK0T7nLTr7ykcIiQeJGEP5q8t/IPaDs2v5yPWHv6cm8v9gCewFnzgv0Kqp0CNidzO2OlS3JmOk8mwdKad7dwpm5TKeJp3d9od35vN7H5uYZdozjfiMI7jXsQa+cfsFWWMTf5uaD0hnJFu93AWC+8xxid+/cihcbY8GA2QjjslUNGKZ0/XsWAcE3MBVyBQLecjDWidyyNbgq/LB0lS8F+U9TKTkrNLqID/HsrGnDlA15NY2Kmz74wYs5tEpm5cJ6PLjaJ+vQ8RlgI6Vk+slExheF1bXoQZrGzdXh6G3ZdPxCKynQ7KUkpRfbpmK6NdAaIf2+B77BnpKRYmLcIkfARv2bugBx571IaN8duAz0JIJIWlubL96eJv7RzzRPrsr378OTjEpO8A+w3LyOprhHJ0MYkmeItMKQKl+k=
|
9
|
+
gem: strudel
|
10
|
+
on:
|
11
|
+
tags: true
|
12
|
+
repo: justinhoward/strudel
|
13
|
+
addons:
|
14
|
+
code_climate:
|
15
|
+
repo_token:
|
16
|
+
secure: "fSiRB01llLIkzTLFuRHKDwTHJYelGo7+T4q1WZq9/qBuulCzIBUS0VdS7YyZIY0WVhrdhDUVIzNmESt3nGguL9By5TasrMi4HkdaL/WQPQnn/nH4vwkyOFex1mYa/lEmUnYW6fdVWvq9aS79P20zUCcK5EBFqmWZ/jTe7ssFV9u88QwR/NOa1gH8uabsBwefFlg8hKWi+G4DKRtNuOF0dGmiE6bG3VAKv/n16WRXIfyzFHDdNdrURJObHTEzEW7+Q7JNDRsuAcaSwGAWQtOC3RZmUKWfvIy33wJE+amIhL0GHhXJ3L2s1W/pSc/eiIMg1zsGJsbeUg2VdE4XFIRY9nRamXYtCl85IYct9P1nSB4mMXC1ezCN4fmYS0CBfsBJqzEw13mRf2G3qk65z5CYPHIdL0qZ2qHvRw2tz+EVShFk9mLd9g57KsbeGcq+7daOcSMVGo4ypEd/fx512kaWdUxzZQlEZ2YqIFFI3na4aC/dZmmSFdlghtSZCtYnxz/6ZzoHvx+9rZrcR3FNNB+A3TDGynRfmIZf1ZBqKBdbrocUZ4dODxaI7/82J+y3pFoS3bmb+8r8NevwPce/QwPTesU7hJ9iBMutGLJ0+A6WB4iBpBAwq0H7awKVkluCw/me8ZAD7Nwf8+SBjWCUXX87KbCG3niF+EtKjljgE3Q3cFk="
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Justin Howard
|
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,124 @@
|
|
1
|
+
# Strudel
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/justinhoward/strudel.svg?branch=master)]
|
4
|
+
(https://travis-ci.org/justinhoward/strudel)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/justinhoward/strudel/badges/gpa.svg)]
|
6
|
+
(https://codeclimate.com/github/justinhoward/strudel)
|
7
|
+
[![Test Coverage](https://codeclimate.com/github/justinhoward/strudel/badges/coverage.svg)]
|
8
|
+
(https://codeclimate.com/github/justinhoward/strudel/coverage)
|
9
|
+
[![Inline docs](http://inch-ci.org/github/justinhoward/strudel.svg?branch=master&style=shields)]
|
10
|
+
(http://inch-ci.org/github/justinhoward/strudel)
|
11
|
+
|
12
|
+
Strudel is a dependency injection container for Ruby. It's a way to organize
|
13
|
+
your Ruby application to take advantage of the [dependency inversion
|
14
|
+
principle][ioc].
|
15
|
+
|
16
|
+
## Why another DI framework?
|
17
|
+
|
18
|
+
Strudel is not a framework. It's one class that serves as a container only. No
|
19
|
+
auto-injection. That means no polluting your classes with garbage injection
|
20
|
+
metaprogramming. You have full, explicit control over how your services
|
21
|
+
are constructed.
|
22
|
+
|
23
|
+
Honestly, you may not even need Strudel or any other DI library. If you are
|
24
|
+
passing your dependencies through your class constructors, you're already doing
|
25
|
+
dependency injection! Strudel simply helps you organize your services and
|
26
|
+
dependencies in one place.
|
27
|
+
|
28
|
+
## But Ruby Doesn't Need Dependency Injection!
|
29
|
+
|
30
|
+
You may have read [this post][dhh] by David Heineimer Hansson. However he
|
31
|
+
didn't address the primary benefit of DI, explicitly defining dependencies.
|
32
|
+
I also happen to think that patching code at runtime for testing is a egregious
|
33
|
+
anti-pattern. In case you need more convincing, check out this
|
34
|
+
[great post][piotr] by Piotr Solnica.
|
35
|
+
|
36
|
+
## Installation
|
37
|
+
|
38
|
+
Add this line to your application's Gemfile:
|
39
|
+
|
40
|
+
```sh
|
41
|
+
gem 'strudel'
|
42
|
+
```
|
43
|
+
|
44
|
+
## Getting Started
|
45
|
+
|
46
|
+
Fist create a new instance of `Strudel`.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
require 'strudel'
|
50
|
+
app = Strudel.new
|
51
|
+
```
|
52
|
+
|
53
|
+
The methods you will use most often are `get` and `set`. These allow you to
|
54
|
+
create and access services.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
# Set a static service
|
58
|
+
app[:api_url] = 'http://example.com/api'
|
59
|
+
|
60
|
+
# Set a shared service
|
61
|
+
app.set(:api) do
|
62
|
+
RestApi.new(app[:api_url])
|
63
|
+
end
|
64
|
+
|
65
|
+
# Now we can access the api service
|
66
|
+
app[:api].request
|
67
|
+
```
|
68
|
+
|
69
|
+
In this example, we set up and use an `api` service.
|
70
|
+
|
71
|
+
- First we use the `[]=` method to create a static service called `api_url`.
|
72
|
+
- Then we create a service called `api`. This time we pass a block into the
|
73
|
+
`set` method. This allows the service to be instantiated asynchronously. The
|
74
|
+
`RestApi` instance won't be created until we use it on the final line.
|
75
|
+
- On the last line, we use the `[]` method to retrieve the instance of `RestApi`
|
76
|
+
and call a `request` method on it. Because of the way we defined the `api`
|
77
|
+
service, the `api.url` parameter will be passed into the `RestApi` constructor
|
78
|
+
when it is created.
|
79
|
+
|
80
|
+
Once it's constructed, the `api` service will be cached, so if we call it again,
|
81
|
+
Strudel will use the same instance of `RestApi`.
|
82
|
+
|
83
|
+
See the API Documentation for more information or to learn about the other
|
84
|
+
available methods:
|
85
|
+
|
86
|
+
- `[]`
|
87
|
+
- `[]=`
|
88
|
+
- `set`
|
89
|
+
- `factory`
|
90
|
+
- `protect`
|
91
|
+
- `extend`
|
92
|
+
- `each`
|
93
|
+
- `include?`
|
94
|
+
|
95
|
+
## API Documentation
|
96
|
+
|
97
|
+
API documentation can be found [inline][inline-docs], or you can generate HTML documentation
|
98
|
+
with yard.
|
99
|
+
|
100
|
+
```sh
|
101
|
+
bin/rake yard
|
102
|
+
```
|
103
|
+
|
104
|
+
## Credits
|
105
|
+
|
106
|
+
Strudel is a port of the JavaScript library [papaya] by [Justin Howard][justin].
|
107
|
+
|
108
|
+
Papaya is originally inspired by [Pimple][pimple], a library for PHP by
|
109
|
+
[Fabien Potencier][fabien].
|
110
|
+
|
111
|
+
## License
|
112
|
+
|
113
|
+
The gem is available as open source under the terms of the [MIT
|
114
|
+
License][mit].
|
115
|
+
|
116
|
+
[ioc]: https://en.wikipedia.org/wiki/Dependency_inversion_principle
|
117
|
+
[dhh]: http://david.heinemeierhansson.com/2012/dependency-injection-is-not-a-virtue.html
|
118
|
+
[piotr]: http://solnic.eu/2013/12/17/the-world-needs-another-post-about-dependency-injection-in-ruby.html
|
119
|
+
[papaya]: https://github.com/justinhoward/papaya
|
120
|
+
[justin]: https://github.com/justinhoward
|
121
|
+
[pimple]: http://pimple.sensiolabs.org
|
122
|
+
[fabien]: https://github.com/fabpot
|
123
|
+
[mit]: http://opensource.org/licenses/MIT
|
124
|
+
[inline-docs]: lib/strudel.rb
|
data/Rakefile
ADDED
data/bin/rake
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rake' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/rspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rspec' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/yard
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'yard' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("yard", "yard")
|
data/bin/yardoc
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'yardoc' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("yard", "yardoc")
|
data/bin/yri
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'yri' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
|
+
|
16
|
+
load Gem.bin_path("yard", "yri")
|
data/lib/strudel.rb
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
# Strudel
|
2
|
+
#
|
3
|
+
# A tiny dependency injection container
|
4
|
+
class Strudel
|
5
|
+
# Creates a new Strudel container
|
6
|
+
#
|
7
|
+
# @yield [self]
|
8
|
+
def initialize
|
9
|
+
@services = {}
|
10
|
+
@procs = {}
|
11
|
+
@factories = {}
|
12
|
+
yield self if block_given?
|
13
|
+
end
|
14
|
+
|
15
|
+
# Get a service by key
|
16
|
+
#
|
17
|
+
# If the service is not set, returns +nil+.
|
18
|
+
#
|
19
|
+
# @param [key] key The service key
|
20
|
+
# @return [value, nil] The service or nil if not set
|
21
|
+
def [](key)
|
22
|
+
return @services[key].call(self) if @factories[key]
|
23
|
+
|
24
|
+
if @procs[key]
|
25
|
+
@services[key] = @services[key].call(self)
|
26
|
+
@procs.delete(key)
|
27
|
+
end
|
28
|
+
|
29
|
+
@services[key]
|
30
|
+
end
|
31
|
+
|
32
|
+
# Set a service by key and value
|
33
|
+
#
|
34
|
+
# If +service+ is a Proc, its return value will be treated as a
|
35
|
+
# singleton service meaning it will be initialized the first time it is
|
36
|
+
# requested and its valud will be cached for subsequent requests.
|
37
|
+
#
|
38
|
+
# Use the +set+ method to allow using a block instead of a Proc argument.
|
39
|
+
#
|
40
|
+
# If +service+ is not a function, its value will be stored directly.
|
41
|
+
#
|
42
|
+
# @param [key] key The service key
|
43
|
+
# @param [Proc, value] service The service singleton Proc or static service
|
44
|
+
# @return [self]
|
45
|
+
def []=(key, service)
|
46
|
+
set(key, service)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Set a service by key and value
|
50
|
+
#
|
51
|
+
# Same as +[]=+ except allows passing a block instead of a Proc argument.
|
52
|
+
#
|
53
|
+
# @param [key] key The service key
|
54
|
+
# @param [Proc, value, nil] service The service singleton Proc or static
|
55
|
+
# service
|
56
|
+
# @yield [self]
|
57
|
+
# @return [self]
|
58
|
+
def set(key, service = nil)
|
59
|
+
create(key, service || Proc.new, @procs)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Set a factory service by key and value
|
63
|
+
#
|
64
|
+
# If +factory+ is a function, it will be called every time the service is
|
65
|
+
# requested. So if it returns an object, it will create a new object for
|
66
|
+
# every request.
|
67
|
+
#
|
68
|
+
# If +factory+ is not a function, this method acts like +set+.
|
69
|
+
#
|
70
|
+
# @param [key] key The service key
|
71
|
+
# @param [Proc, block] factory The service factory Proc or static service
|
72
|
+
# @yield [self]
|
73
|
+
# @return [self]
|
74
|
+
def factory(key, factory = nil)
|
75
|
+
create(key, factory || Proc.new, @factories)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Set a protected service by name and value
|
79
|
+
#
|
80
|
+
# If +service+ is a function, the function itself will be registered as a
|
81
|
+
# service. So when it is requested with +get+, the function will be returned
|
82
|
+
# instead of the function's return value.
|
83
|
+
#
|
84
|
+
# If +service+ is not a function, this method acts like +set+.
|
85
|
+
#
|
86
|
+
# @param [key] key The service key
|
87
|
+
# @param [Proc, value, nil] service The service function.
|
88
|
+
# @yield [self]
|
89
|
+
# @return [self]
|
90
|
+
def protect(key, service = nil)
|
91
|
+
create(key, service || Proc.new)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Extends an existing service and overrides it.
|
95
|
+
#
|
96
|
+
# The +extender+ block will be called with 2 arguments: +old_value+ and
|
97
|
+
# +self+. If there is no existing +key+ service, +old_value+ will be nil. It
|
98
|
+
# should return the new value for the service that will override the existing
|
99
|
+
# one.
|
100
|
+
#
|
101
|
+
# If +extend+ is called for a service that was created with +set+, the
|
102
|
+
# resulting service will be a singleton.
|
103
|
+
#
|
104
|
+
# If +extend+ is called for a service that was created with +factory+, the
|
105
|
+
# resulting service will be a factory.
|
106
|
+
#
|
107
|
+
# If +extend+ is called for a service that was created with +protect+, the
|
108
|
+
# resulting service will also be protected.
|
109
|
+
#
|
110
|
+
# If +extender+ is not a function, this method will override any existing
|
111
|
+
# service like +set+.
|
112
|
+
#
|
113
|
+
# @param [key] key The service key
|
114
|
+
# @param [Proc, value, nil] extender
|
115
|
+
# @yield [old_value, self]
|
116
|
+
# @return [self]
|
117
|
+
def extend(key, extender = nil)
|
118
|
+
extender ||= Proc.new
|
119
|
+
return set(key, extender) unless extender.is_a?(Proc) && @services.key?(key)
|
120
|
+
|
121
|
+
extended = @services[key]
|
122
|
+
call = @factories[key] || @procs[key]
|
123
|
+
send(@factories[key] ? :factory : :set, key) do
|
124
|
+
extender.call(self, call ? extended.call(self) : extended)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Iterates over the service keys
|
129
|
+
#
|
130
|
+
# If a block is given, the block is called with each of the service keys
|
131
|
+
# If a block is not given, returns an +Enumerable+ of the keys.
|
132
|
+
#
|
133
|
+
# The key order is undefined.
|
134
|
+
#
|
135
|
+
# @yield [key] Gives the key
|
136
|
+
# @return [Enumerable, nil]
|
137
|
+
def each
|
138
|
+
return @services.each_key unless block_given?
|
139
|
+
@services.each_key { |key| yield key }
|
140
|
+
end
|
141
|
+
|
142
|
+
# Checks if a service for +key+ exists.
|
143
|
+
#
|
144
|
+
# @return [bool] True if the service exists.
|
145
|
+
def include?(key)
|
146
|
+
@services.key?(key)
|
147
|
+
end
|
148
|
+
|
149
|
+
private
|
150
|
+
|
151
|
+
# Create a service
|
152
|
+
#
|
153
|
+
# @param [key] key The service key
|
154
|
+
# @param [value] service The service value or factory
|
155
|
+
# @param [Hash] registry If the service is a proc, the registery
|
156
|
+
def create(key, service, registry = nil)
|
157
|
+
[@procs, @factories].each { |reg| reg.delete key }
|
158
|
+
registry[key] = true if registry && service.is_a?(Proc)
|
159
|
+
@services[key] = service
|
160
|
+
self
|
161
|
+
end
|
162
|
+
end
|
data/strudel.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'strudel'
|
7
|
+
spec.version = '0.1.0'
|
8
|
+
spec.authors = ['Justin Howard']
|
9
|
+
spec.email = ['jmhoward0@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'A tiny dependency injection container'
|
12
|
+
spec.homepage = 'https://github.com/justinhoward/strudel'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(spec)/})
|
17
|
+
end
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
21
|
+
spec.add_development_dependency 'rspec'
|
22
|
+
spec.add_development_dependency 'yard'
|
23
|
+
spec.add_development_dependency 'simplecov'
|
24
|
+
spec.add_development_dependency 'rubocop'
|
25
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: strudel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Howard
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: codeclimate-test-reporter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- jmhoward0@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .rspec
|
106
|
+
- .rubocop.yml
|
107
|
+
- .travis.yml
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/rake
|
113
|
+
- bin/rspec
|
114
|
+
- bin/yard
|
115
|
+
- bin/yardoc
|
116
|
+
- bin/yri
|
117
|
+
- lib/strudel.rb
|
118
|
+
- strudel.gemspec
|
119
|
+
homepage: https://github.com/justinhoward/strudel
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.4.5
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: A tiny dependency injection container
|
143
|
+
test_files: []
|