dependency_bundle 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +7 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +13 -2
- data/README.adoc +34 -23
- data/lib/dependency_bundle.rb +22 -12
- data/lib/dependency_bundle/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de42a0c02b932ffa098f92eaf23a15bcd76eb13bc36817f754df43c2c44f1fcf
|
4
|
+
data.tar.gz: 36a9cfaef6f2b7f4efe42ba2f748617df2bb875d1611929999deb440c4c23e33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea5b4526704e0fb34d35c58f92f2b6c9fb12d76c8171f8ce237c7ecda5ef542f2d7e77a0576ea8e27eb268a7c1c3441e72d582af7c5c8e89aaff1c52baac9e5f
|
7
|
+
data.tar.gz: 609741c77cedad3362f990054770f611a1ae4d8e70242eb408ad5677f615b3e7a92c7fc6319cc0b61ba00674f7d96aa0b87a19b67bdbff400e059edfa906e8d5
|
data/.gitlab-ci.yml
ADDED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dependency_bundle (
|
4
|
+
dependency_bundle (1.0.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
byebug (9.1.0)
|
10
10
|
coderay (1.1.2)
|
11
|
+
coveralls (0.8.22)
|
12
|
+
json (>= 1.8, < 3)
|
13
|
+
simplecov (~> 0.16.1)
|
14
|
+
term-ansicolor (~> 1.3)
|
15
|
+
thor (~> 0.19.4)
|
16
|
+
tins (~> 1.6)
|
11
17
|
diff-lcs (1.3)
|
12
18
|
docile (1.3.1)
|
13
19
|
git (1.5.0)
|
@@ -40,12 +46,17 @@ GEM
|
|
40
46
|
simplecov-html (0.10.2)
|
41
47
|
structured_changelog (0.11.0)
|
42
48
|
git
|
49
|
+
term-ansicolor (1.7.0)
|
50
|
+
tins (~> 1.0)
|
51
|
+
thor (0.19.4)
|
52
|
+
tins (1.20.2)
|
43
53
|
|
44
54
|
PLATFORMS
|
45
55
|
ruby
|
46
56
|
|
47
57
|
DEPENDENCIES
|
48
58
|
bundler (~> 1.16)
|
59
|
+
coveralls
|
49
60
|
dependency_bundle!
|
50
61
|
pry-byebug
|
51
62
|
rake (~> 10.0)
|
@@ -54,4 +65,4 @@ DEPENDENCIES
|
|
54
65
|
structured_changelog
|
55
66
|
|
56
67
|
BUNDLED WITH
|
57
|
-
1.
|
68
|
+
1.17.3
|
data/README.adoc
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
:linkattrs:
|
6
6
|
:icons: font
|
7
7
|
:toc: macro
|
8
|
+
:toc-title:
|
8
9
|
:toclevels: 3
|
9
10
|
ifdef::env-github[]
|
10
11
|
:tip-caption: :bulb:
|
@@ -14,9 +15,9 @@ ifdef::env-github[]
|
|
14
15
|
:warning-caption: :warning:
|
15
16
|
endif::[]
|
16
17
|
|
17
|
-
https://badge.fury.io/rb/dependency_bundle[
|
18
|
-
https://travis-ci.org/yarmiganosca/dependency_bundle[
|
19
|
-
https://coveralls.io/
|
18
|
+
image:https://badge.fury.io/rb/dependency_bundle.svg["Gem Version", link="https://badge.fury.io/rb/dependency_bundle"]
|
19
|
+
image:https://travis-ci.org/yarmiganosca/dependency_bundle.svg?branch=master["Build Status", link="https://travis-ci.org/yarmiganosca/dependency_bundle"]
|
20
|
+
image:https://coveralls.io/repos/github/yarmiganosca/dependency_bundle/badge.svg?branch=master["Test Coverage", link="https://coveralls.io/github/yarmiganosca/dependency_bundle?branch=master"]
|
20
21
|
|
21
22
|
toc::[]
|
22
23
|
|
@@ -33,14 +34,14 @@ Instead, DependencyBundle is a Depedency Registry that's designed to be injected
|
|
33
34
|
----
|
34
35
|
require 'dependency_bundle'
|
35
36
|
|
36
|
-
deps = DependencyBundle.new
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
deps = DependencyBundle.new
|
38
|
+
# by default, DependencyBundle instances also come with:
|
39
|
+
# .env -> the ENV global
|
40
|
+
# .stdin -> the STDIN global
|
41
|
+
# .stdout -> the STDOUT global
|
42
|
+
# .stderr -> the STDERR global
|
43
|
+
|
44
|
+
deps.set(logger: Logger.new(deps.stdout))
|
44
45
|
----
|
45
46
|
|
46
47
|
But building your entire codebase around it is even better.
|
@@ -67,14 +68,17 @@ So your bundle would look something like this:
|
|
67
68
|
----
|
68
69
|
require 'dependency_bundle'
|
69
70
|
|
70
|
-
deps = DependencyBundle.new
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
71
|
+
deps = DependencyBundle.new
|
72
|
+
|
73
|
+
deps.set(logger: Logger.new(self.stdout)) # default DependencyBundle stdout
|
74
|
+
deps.set(
|
75
|
+
mailer: Mailer(deps: self)), # Mailer needs a logger, so we inject deps into it
|
76
|
+
http_client: HTTPClient.new(deps: self)), # the HTTPClient also needs a logger
|
77
|
+
memcache_client: MemcacheClient.new( # MemcacheClient needs:
|
78
|
+
host: "cache.example.com", # a host to connect to
|
79
|
+
deps: self # a logger, which we again get from our DependencyBundle
|
77
80
|
)
|
81
|
+
)
|
78
82
|
end
|
79
83
|
----
|
80
84
|
|
@@ -121,10 +125,12 @@ Testing your code with Dependency Bundles is also easy! Build `DependencyBundle`
|
|
121
125
|
----
|
122
126
|
RSpec.describe MorningMeetingReport do
|
123
127
|
let(:deps) do
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
+
DependencyBundle.new(
|
129
|
+
logger: Logger.new(StringIO.new),
|
130
|
+
mailer: instance_double("Mailer"),
|
131
|
+
http_client: instance_double('HTTPClient'),
|
132
|
+
memcache_client: instance_double('MemcacheClient')
|
133
|
+
)
|
128
134
|
end
|
129
135
|
|
130
136
|
context 'happy path' do
|
@@ -182,7 +188,12 @@ To install this gem onto your local machine, run `bundle exec rake install`.
|
|
182
188
|
|
183
189
|
=== Testing
|
184
190
|
|
185
|
-
To run all the tests, run
|
191
|
+
To run all the tests, run
|
192
|
+
|
193
|
+
[subs=+macros]
|
194
|
+
----
|
195
|
+
+++<span style="pointer-events:none;user-select:none;">$ </span>+++bundle exec rspec
|
196
|
+
----
|
186
197
|
|
187
198
|
=== Pull Requests
|
188
199
|
|
data/lib/dependency_bundle.rb
CHANGED
@@ -4,20 +4,20 @@ class DependencyBundle
|
|
4
4
|
DependencyNotProvided = Class.new(StandardError)
|
5
5
|
OverrideAttempted = Class.new(StandardError)
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
set
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
def initialize(**dependencies)
|
8
|
+
set(
|
9
|
+
{
|
10
|
+
env: ENV,
|
11
|
+
stdin: STDIN,
|
12
|
+
stdout: STDOUT,
|
13
|
+
stderr: STDERR,
|
14
|
+
}.merge(**dependencies)
|
15
|
+
)
|
14
16
|
end
|
15
17
|
|
16
|
-
def set(
|
17
|
-
|
18
|
-
|
19
|
-
else
|
20
|
-
define_singleton_method(name) { value }
|
18
|
+
def set(**dependencies)
|
19
|
+
dependencies.each do |name, dependency|
|
20
|
+
set_single_dependency(name, dependency)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -30,4 +30,14 @@ class DependencyBundle
|
|
30
30
|
|
31
31
|
true
|
32
32
|
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def set_single_dependency(name, value)
|
37
|
+
if respond_to?(name)
|
38
|
+
raise(OverrideAttempted, "You can't override `:#{name}` on #{inspect}, since it already responds to `:#{name}`. If you're seeing this because you tried to override a dependency, please don't. DependencyBundle doesn't allow that because of the misery it would introduce into debugging (your logger or http client changing between constructors is just asking for trouble). If you didn't try to override a dependency, and there's just a pre-existing Ruby method that happens to be named the same as the key you're using, I'm sorry. Please register your dependency with a different key.")
|
39
|
+
else
|
40
|
+
define_singleton_method(name) { value }
|
41
|
+
end
|
42
|
+
end
|
33
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dependency_bundle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Hoffman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,6 +102,7 @@ extensions: []
|
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
104
|
- ".gitignore"
|
105
|
+
- ".gitlab-ci.yml"
|
105
106
|
- ".rspec"
|
106
107
|
- ".travis.yml"
|
107
108
|
- CHANGELOG.md
|