fabrique 0.0.1 → 0.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: 8683ae625b53e11ecf2abd341320e42a060906fc
4
- data.tar.gz: 34b2ae0dc2fb5aa5b8436ab1b275e19f388a9484
3
+ metadata.gz: fcf209a41cd39284e0ecbc2c78e3785bc0f677e4
4
+ data.tar.gz: 67117224f5f81c5deb5b0708334633f69f23bba2
5
5
  SHA512:
6
- metadata.gz: ebaa94d196dde76335b23b3d5b78212d9d71d41cced7c950479561c8ea5a0ea85c59c069dfa1478dbe34a3a17bf1b61ade882d2c357b2d183c05ad03836d30c4
7
- data.tar.gz: 326909d817f1a2ba15e8363fe21e74e5c5419ce199306b5bda2609eb3a34bc485120661c2895b99100abd37c43271ddc03fd9773dad12a68f55378ca604a356a
6
+ metadata.gz: a542c2ee2ebf3086ef5287b436bb7c91794b8c7eb85cb27e3e9ffbd4d0dfd08cf58f10e6a597677bd5fd27e2e80b3a675175f45dec1b830b011cebb1be86872f
7
+ data.tar.gz: 202da5c74f8b0021c9c19722cf5cfc3bb53acc0f0ea86c13a6db16bd93dac4511fba2e5b061eedd18660ec0dce4bb2c3455a3424df9fc81baa504d59db99609c
@@ -208,6 +208,28 @@ Feature: Bean Factory
208
208
  Then the "disco_cube" bean has "mesh" set to the "cube_mesh" bean
209
209
  And the "disco_cube" bean has "scale" that is the Integer 10
210
210
 
211
+ Scenario: Inner bean
212
+
213
+ Given I have a YAML application context definition:
214
+ """
215
+ ---
216
+ beans:
217
+ - id: outer
218
+ class: Fabrique::Test::Fixtures::Constructors::ClassWithPositionalArgumentConstructor
219
+ constructor_args:
220
+ - large
221
+ - red
222
+ - !bean
223
+ class: Fabrique::Test::Fixtures::Constructors::ClassWithPositionalArgumentConstructor
224
+ constructor_args:
225
+ - infinite
226
+ - invisible
227
+ - elephant
228
+ """
229
+ When I request a bean factory for the application context
230
+ And I request the "outer" bean from the bean factory
231
+ Then the bean's "shape" is an object with "shape" set to "elephant"
232
+
211
233
  Scenario: Singleton bean (default)
212
234
 
213
235
  Given I have a YAML application context definition:
@@ -1,4 +1,4 @@
1
- require "yaml"
1
+ require "tempfile"
2
2
 
3
3
  After do
4
4
  if defined?(@tmpfile) and File.exists?(@tmpfile)
@@ -25,6 +25,10 @@ Then(/^the bean has "(.*?)" set to "(.*?)"$/) do |attr, value|
25
25
  expect(@bean.send(attr)).to eql value
26
26
  end
27
27
 
28
+ Then(/^the bean's "(.*?)" is an object with "(.*?)" set to "(.*?)"$/) do |attr, child_attr, value|
29
+ expect(@bean.send(attr).send(child_attr)).to eql value
30
+ end
31
+
28
32
  Then(/^the bean has "(.*?)" that is the Integer "(.*?)"$/) do |attr, int_value|
29
33
  expect(@bean.send(attr)).to eql int_value.to_i
30
34
  end
@@ -23,21 +23,25 @@ module Fabrique
23
23
  def get_bean_unsynchronized(bean_name)
24
24
  defn = @registry.get_definition(bean_name)
25
25
 
26
+ if defn.singleton? and singleton = @singletons[bean_name]
27
+ return singleton
28
+ end
29
+
30
+ get_bean_by_definition(defn).tap do |bean|
31
+ if defn.singleton?
32
+ @singletons[bean_name] = bean
33
+ end
34
+ end
35
+ end
36
+
37
+ def get_bean_by_definition(defn)
26
38
  if defn.factory_method == "itself"
27
39
  # Support RUBY_VERSION < 2.2.0 (missing Kernel#itself)
28
40
  return defn.type
29
41
  end
30
42
 
31
- if defn.singleton? and singleton = @singletons[bean_name]
32
- return singleton
33
- end
34
-
35
43
  bean = constructor_injection(defn)
36
44
  property_injection(bean, defn)
37
- if defn.singleton?
38
- @singletons[bean_name] = bean
39
- end
40
- bean
41
45
  end
42
46
 
43
47
  def constructor_injection(defn)
@@ -67,6 +71,8 @@ module Fabrique
67
71
  data.inject([]) do |acc, v|
68
72
  acc << resolve_bean_references(v)
69
73
  end
74
+ elsif data.is_a?(BeanDefinition)
75
+ get_bean_by_definition(data)
70
76
  elsif data.is_a?(BeanReference)
71
77
  get_bean_unsynchronized(data.bean)
72
78
  else
@@ -1,3 +1,3 @@
1
1
  module Fabrique
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fabrique
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sheldon Hearn
@@ -14,70 +14,70 @@ dependencies:
14
14
  name: liquid
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.7'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.7'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.2'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.2'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: cucumber
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.3'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.3'
83
83
  description: Factory support library for adapting existing modules for injection as
@@ -88,11 +88,11 @@ executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
- - ".gitignore"
92
- - ".rspec"
93
- - ".ruby-gemset"
94
- - ".ruby-version"
95
- - ".travis.yml"
91
+ - .gitignore
92
+ - .rspec
93
+ - .ruby-gemset
94
+ - .ruby-version
95
+ - .travis.yml
96
96
  - Gemfile
97
97
  - Guardfile
98
98
  - LICENSE.txt
@@ -152,12 +152,12 @@ require_paths:
152
152
  - lib
153
153
  required_ruby_version: !ruby/object:Gem::Requirement
154
154
  requirements:
155
- - - ">="
155
+ - - '>='
156
156
  - !ruby/object:Gem::Version
157
157
  version: '2.0'
158
158
  required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  requirements:
160
- - - ">="
160
+ - - '>='
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0'
163
163
  requirements: []