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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44823d9bfdaf9b6c44a0608b7a13a0f6fcdec235adfa462b236c692c0727b99c
4
- data.tar.gz: c827b37f403b10835d2904fbd8c975452a2abca50232c799fa8ac8c59131730f
3
+ metadata.gz: de42a0c02b932ffa098f92eaf23a15bcd76eb13bc36817f754df43c2c44f1fcf
4
+ data.tar.gz: 36a9cfaef6f2b7f4efe42ba2f748617df2bb875d1611929999deb440c4c23e33
5
5
  SHA512:
6
- metadata.gz: bee3954383ada6a2ec98b411e0cab0a761fe6b15ce01b2aa3adade10e54f20409e2903f60ab7e719ac652609f8005567ee23e358aeb9e931b1767a4d601987dc
7
- data.tar.gz: 59ce7706fe7103af008f9c53e9cdd68da1ea7280dcc8d3501b149ea0b01268e9013b17d71623ae75f7a2a2ddee0fb9e036721b7cde4d6b6dbcb6727d7b40720d
6
+ metadata.gz: ea5b4526704e0fb34d35c58f92f2b6c9fb12d76c8171f8ce237c7ecda5ef542f2d7e77a0576ea8e27eb268a7c1c3441e72d582af7c5c8e89aaff1c52baac9e5f
7
+ data.tar.gz: 609741c77cedad3362f990054770f611a1ae4d8e70242eb408ad5677f615b3e7a92c7fc6319cc0b61ba00674f7d96aa0b87a19b67bdbff400e059edfa906e8d5
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,7 @@
1
+ before_script:
2
+ - gem install bundler -v '< 2'
3
+ - bundle install
4
+
5
+ rspec:
6
+ image: ruby:2.5.1
7
+ script: bundle exec rspec
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## RELEASE 1.0.0
2
+
3
+ * BREAKING: Changed the `#initialize` and `#set` method signatures.
4
+
1
5
  ## RELEASE 0.1.0
2
6
 
3
7
  * FEATURE: It exists. See the README for instructions.
data/Gemfile CHANGED
@@ -4,3 +4,5 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in dependency_bundle.gemspec
6
6
  gemspec
7
+
8
+ gem 'coveralls', require: false
data/Gemfile.lock CHANGED
@@ -1,13 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dependency_bundle (0.1.0)
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.16.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[image:https://badge.fury.io/rb/dependency_bundle.png[Gem Version]]
18
- https://travis-ci.org/yarmiganosca/dependency_bundle[image:https://secure.travis-ci.org/yarmiganosca/dependency_bundle.png[Build Status]]
19
- https://coveralls.io/r/yarmiganosca/dependency_bundle[image:https://coveralls.io/repos/yarmiganosca/dependency_bundle/badge.png?branch=master[Test Coverage]]
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 do
37
- set :logger, Logger.new(self.stdout) # self is the DependencyBundle instance
38
- # by default, DependencyBundle instances come with:
39
- # :env -> the ENV global
40
- # :stdin -> the STDIN global
41
- # :stdout -> the STDOUT global
42
- # :stderr -> the STDERR global
43
- end
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 do
71
- set :logger, Logger.new(self.stdout) # each DependencyBundle has stdout by default
72
- set :mailer, Mailer(deps: self) # which needs a logger
73
- set :http_client, HTTPClient.new(deps: self) # also needs a logger
74
- set :memcache_client, MemcacheClient.new(
75
- host: "cache.example.com", # needs a host to connect to
76
- deps: self # needs a logger
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
- set :logger, Logger.new(StringIO.new)
125
- set :mailer, instance_double('Mailer')
126
- set :http_client, instance_double('HTTPClient')
127
- set :memcache_client, instance_double('MemcacheClient')
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 `bundle exec rspec`.
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
 
@@ -4,20 +4,20 @@ class DependencyBundle
4
4
  DependencyNotProvided = Class.new(StandardError)
5
5
  OverrideAttempted = Class.new(StandardError)
6
6
 
7
- def initialize(&blk)
8
- set :env, ENV
9
- set :stdin, STDIN
10
- set :stdout, STDOUT
11
- set :stderr, STDERR
12
-
13
- instance_exec(&blk) if block_given?
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(name, value)
17
- if respond_to?(name)
18
- 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.")
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
@@ -1,3 +1,3 @@
1
1
  class DependencyBundle
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  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: 0.1.0
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: 2018-12-08 00:00:00.000000000 Z
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