injectable_dependencies 1.0.0 → 1.1.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
  SHA1:
3
- metadata.gz: d8f1b46e73121f4e9722086542e7fcad5c374d73
4
- data.tar.gz: 96f3836a8ba0532a3c549fad639ec68a16cd83dc
3
+ metadata.gz: 061ab1c3ffd232aff0541defb77b8491d670421b
4
+ data.tar.gz: 1be76a0ab83cf9a50690543c85780e9309d30591
5
5
  SHA512:
6
- metadata.gz: 32817c025f48f7ab4b2c2d1ca30c7ffaa9c41ef785120b74cc0534b9a186d26b6278b11a30a100f830b2e260279e69de7c5088864d4964907846453d35d5e3f6
7
- data.tar.gz: 054b2933e6443a529ca9ac6258efb6bf0c9df694c8911577879badc597236ee6b9192f274635cd57d8dbd4bd3629d0c8b3932e5a4a5c1e2b7e61d0a27f8d2e00
6
+ metadata.gz: cc5a0a1b6aa5eaf381d56dfd50e6fb540ff65e5a407fe5209f652db692ecaf73d00fe3dc8fb2159da1066ef23d76a705a3d31fb7df15ab92040d06cff5448b80
7
+ data.tar.gz: 680bc81279cd67075c31de0beb357d2ec802a7430442fee92ade32f92ddb525d4eabdad7c6cc76e75458221097d6bb08e70a60626e2915af3e3708159e8f1990
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ bin/
@@ -1,3 +1,3 @@
1
1
  module InjectableDependencies
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -17,12 +17,18 @@ require 'active_support/concern'
17
17
  #
18
18
  module InjectableDependencies
19
19
  UndeclaredDependencyError = Class.new(StandardError)
20
+ MissingImplementationError = Class.new(StandardError)
21
+
20
22
  extend ActiveSupport::Concern
21
23
 
22
24
  module ClassMethods
23
- def dependency(name, &proc)
25
+ def dependency(name, &block)
24
26
  dependencies << name
25
- define_method(name, &proc) # available to all instances
27
+ if block
28
+ define_method(name, &block) # available to all instances
29
+ else
30
+ no_default_dependencies << name
31
+ end
26
32
  end
27
33
 
28
34
  protected
@@ -30,10 +36,19 @@ module InjectableDependencies
30
36
  def dependencies
31
37
  @dependencies ||= []
32
38
  end
39
+
40
+ def no_default_dependencies
41
+ @no_default_dependencies ||= []
42
+ end
33
43
  end
34
44
 
35
45
  def initialize_dependencies(overrides = {})
36
46
  return unless overrides
47
+ self.class.send(:no_default_dependencies).each do |name|
48
+ unless overrides.has_key?(name)
49
+ raise MissingImplementationError.new("No implementation was provided for dependency ##{name}")
50
+ end
51
+ end
37
52
  overrides.each do |k,v|
38
53
  unless self.class.send(:dependencies).include?(k)
39
54
  raise UndeclaredDependencyError, "Cannot override undeclared dependency '#{k}'."
@@ -46,4 +46,22 @@ describe InjectableDependencies do
46
46
  .to raise_error(InjectableDependencies::UndeclaredDependencyError,
47
47
  "Cannot override undeclared dependency 'undeclared_thing'.")
48
48
  end
49
+
50
+ context 'when a dependency is defined without a default implementation' do
51
+ let(:dependent_class) {
52
+ Class.new do
53
+ include InjectableDependencies
54
+ dependency(:baz)
55
+ def initialize(dependencies = {})
56
+ initialize_dependencies(dependencies)
57
+ end
58
+ end
59
+ }
60
+
61
+ it 'raises an error if an implementation is not provided during dependency initialization' do
62
+ expect{ dependent_class.new }.to \
63
+ raise_error(InjectableDependencies::MissingImplementationError,
64
+ 'No implementation was provided for dependency #baz')
65
+ end
66
+ end
49
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: injectable_dependencies
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Wilger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-30 00:00:00.000000000 Z
11
+ date: 2014-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport