fabrique 0.1.0 → 0.3.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: fcf209a41cd39284e0ecbc2c78e3785bc0f677e4
4
- data.tar.gz: 67117224f5f81c5deb5b0708334633f69f23bba2
3
+ metadata.gz: 494331a7b6792524ef6015df1561d1491e2f8c42
4
+ data.tar.gz: cb74ab2e30ffa97f9e6b4e7a13c189efcc3437a1
5
5
  SHA512:
6
- metadata.gz: a542c2ee2ebf3086ef5287b436bb7c91794b8c7eb85cb27e3e9ffbd4d0dfd08cf58f10e6a597677bd5fd27e2e80b3a675175f45dec1b830b011cebb1be86872f
7
- data.tar.gz: 202da5c74f8b0021c9c19722cf5cfc3bb53acc0f0ea86c13a6db16bd93dac4511fba2e5b061eedd18660ec0dce4bb2c3455a3424df9fc81baa504d59db99609c
6
+ metadata.gz: dd994b6430c7d1635b489928a0684caba53fcc64ceca9c6de2b8762e98c65655916e0ea41b8879bfda97cdfa973ab2b3c7d44d40959c023cf6f8c0763b6dd954
7
+ data.tar.gz: b66bd347ef6fded060d9a48a99d117b945b8a1a46fe0667319acf709a140a1554108db5cd35b452182d3fb4e1f49221b83968713b81f11fc1ce5cd238562c3fe
data/Gemfile CHANGED
@@ -4,6 +4,6 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :devtools do
7
- gem "guard-cucumber", "~> 1.5"
8
- gem "byebug", "~> 3.5"
7
+ gem "guard-cucumber", "~> 1.6"
8
+ gem "byebug", "~> 6.0"
9
9
  end
data/fabrique.gemspec CHANGED
@@ -19,10 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "liquid", "~> 3.0"
23
-
24
22
  spec.add_development_dependency "bundler", "~> 1.7"
25
23
  spec.add_development_dependency "rake", "~> 10.0"
26
24
  spec.add_development_dependency "rspec", "~> 3.2"
27
- spec.add_development_dependency "cucumber", "~> 1.3"
25
+ spec.add_development_dependency "cucumber", "~> 2.0"
28
26
  end
@@ -230,6 +230,31 @@ Feature: Bean Factory
230
230
  And I request the "outer" bean from the bean factory
231
231
  Then the bean's "shape" is an object with "shape" set to "elephant"
232
232
 
233
+ Scenario: Bean property reference
234
+
235
+ Given I have a YAML application context definition:
236
+ """
237
+ ---
238
+ beans:
239
+ - id: left
240
+ class: Fabrique::Test::Fixtures::Constructors::ClassWithPositionalArgumentConstructor
241
+ constructor_args:
242
+ - !bean/property_ref right.size
243
+ - !bean/property_ref right.color
244
+ - !bean/property_ref right.shape
245
+ - id: right
246
+ class: Fabrique::Test::Fixtures::Constructors::ClassWithPositionalArgumentConstructor
247
+ constructor_args:
248
+ - tiny
249
+ - purple
250
+ - elephant
251
+ """
252
+ When I request a bean factory for the application context
253
+ And I request the "left" bean from the bean factory
254
+ Then the bean has "size" set to "tiny"
255
+ And the bean has "color" set to "purple"
256
+ And the bean has "shape" set to "elephant"
257
+
233
258
  Scenario: Singleton bean (default)
234
259
 
235
260
  Given I have a YAML application context definition:
@@ -1,20 +1,19 @@
1
1
  require "tempfile"
2
2
 
3
3
  After do
4
- if defined?(@tmpfile) and File.exists?(@tmpfile)
5
- File.unlink(@tmpfile)
4
+ if defined?(@tmpfile) and File.exists?(@tmpfile.path)
5
+ @tmpfile.unlink
6
6
  end
7
7
  end
8
8
 
9
9
  Given(/^I have a YAML application context definition:$/) do |string|
10
- Tempfile.open('fabrique') do |f|
11
- @tmpfile = f.path
12
- f.write(string)
13
- end
10
+ @tmpfile = Tempfile.open('fabrique')
11
+ @tmpfile.write string
12
+ @tmpfile.close
14
13
  end
15
14
 
16
15
  When(/^I request a bean factory for the application context$/) do
17
- @bean_factory = Fabrique::YamlBeanFactory.new(@tmpfile)
16
+ @bean_factory = Fabrique::YamlBeanFactory.new(@tmpfile.path)
18
17
  end
19
18
 
20
19
  When(/^I request the "(.*?)" bean from the bean factory$/) do |bean_name|
@@ -60,7 +59,7 @@ Then(/^I get a different object when I request the "(.*?)" bean again$/) do |bea
60
59
  end
61
60
 
62
61
  Then(/^I get a cyclic bean dependency error when I request a bean factory for the application context$/) do
63
- expect { Fabrique::YamlBeanFactory.new(@tmpfile) }.to raise_error(Fabrique::CyclicBeanDependencyError, /cyclic bean dependency error/)
62
+ expect { Fabrique::YamlBeanFactory.new(@tmpfile.path) }.to raise_error(Fabrique::CyclicBeanDependencyError, /cyclic bean dependency error/)
64
63
  end
65
64
 
66
65
  Then(/^the "(.*?)" and "(.*?)" beans share the same "(.*?)"$/) do |bean1_name, bean2_name, shared_property|
@@ -120,7 +120,7 @@ end
120
120
  require "fabrique"
121
121
 
122
122
  Before do |scenario|
123
- if scenario.source_tags.any? { |tag| tag.name == "@plugin_registry" }
123
+ if scenario.tags.any? { |tag| tag.name == "@plugin_registry" }
124
124
  @test = PluginRegistryTestRunner.new( -> {Fabrique::PluginRegistry.new("Test plugin registry")})
125
125
  end
126
126
  end
@@ -35,7 +35,7 @@ module Fabrique
35
35
  data.each do |o|
36
36
  dependencies_of(o, acc)
37
37
  end
38
- elsif data.is_a?(BeanReference)
38
+ elsif data.is_a?(BeanReference) or data.is_a?(BeanPropertyReference)
39
39
  acc << data
40
40
  end
41
41
  acc
@@ -75,6 +75,8 @@ module Fabrique
75
75
  get_bean_by_definition(data)
76
76
  elsif data.is_a?(BeanReference)
77
77
  get_bean_unsynchronized(data.bean)
78
+ elsif data.is_a?(BeanPropertyReference)
79
+ get_bean_unsynchronized(data.bean).send(data.property)
78
80
  else
79
81
  data
80
82
  end
@@ -0,0 +1,11 @@
1
+ module Fabrique
2
+
3
+ class BeanPropertyReference
4
+ attr :bean, :property
5
+
6
+ def initialize(bean_property)
7
+ @bean, @property = bean_property.split('.')
8
+ end
9
+ end
10
+
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Fabrique
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -3,6 +3,7 @@ require_relative "bean_definition_registry"
3
3
  require_relative "bean_definition"
4
4
  require_relative "bean_factory"
5
5
  require_relative "bean_reference"
6
+ require_relative "bean_property_reference"
6
7
 
7
8
  module Fabrique
8
9
 
@@ -18,20 +19,39 @@ module Fabrique
18
19
  BeanReference.new(value)
19
20
  end
20
21
 
22
+ YAML.add_domain_type("starjuice.net,2015-03-13", "bean/property_ref") do |type, value|
23
+ BeanPropertyReference.new(value)
24
+ end
25
+
21
26
  class YamlBeanFactory < BeanFactory
22
27
 
23
- def initialize(pathname)
24
- data = YAML.load_file(pathname)
25
- if data.respond_to?(:keys) and data["beans"]
26
- beans = data["beans"]
28
+ def initialize(path_or_string)
29
+ super bean_definition_registry beans_node load_yaml path_or_string
30
+ end
31
+
32
+ private
33
+
34
+ def load_yaml(path_or_string)
35
+ if path_or_string.is_a?(String) and path_or_string =~ /\A---\r?\n/
36
+ YAML.load(path_or_string)
37
+ else
38
+ YAML.load_file(path_or_string)
39
+ end
40
+ end
41
+
42
+ def beans_node(parsed_yaml)
43
+ if parsed_yaml.respond_to?(:keys) and parsed_yaml["beans"]
44
+ parsed_yaml["beans"]
27
45
  else
28
46
  raise "YAML contains no top-level beans node"
29
47
  end
48
+ end
30
49
 
50
+ def bean_definition_registry(beans)
31
51
  if beans.is_a?(BeanDefinitionRegistry)
32
- super(beans)
52
+ beans
33
53
  elsif beans.is_a?(Array)
34
- super(BeanDefinitionRegistry.new(beans))
54
+ BeanDefinitionRegistry.new(beans)
35
55
  else
36
56
  raise "YAML top-level beans node must be an Array or a #{BeanDefinitionRegistry}"
37
57
  end
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+ require "tempfile"
3
+
4
+ describe Fabrique::YamlBeanFactory do
5
+
6
+ let(:yaml_context_string) {
7
+ "---\n" \
8
+ "beans: !beans\n" \
9
+ "- !bean\n" \
10
+ " id: simple_object\n" \
11
+ " class: Fabrique::Test::Fixtures::Constructors::ClassWithDefaultConstructor\n"
12
+ }
13
+
14
+ after(:each) do
15
+ @tmpfile.unlink if @tmpfile
16
+ end
17
+
18
+ it "constructs from a YAML application context definition file" do
19
+ @tmpfile = Tempfile.open('fabrique')
20
+ @tmpfile.write yaml_context_string
21
+ @tmpfile.close
22
+
23
+ bean_factory = Fabrique::YamlBeanFactory.new(@tmpfile.path)
24
+ expect(bean_factory.get_bean('simple_object')).to be_a(Fabrique::Test::Fixtures::Constructors::ClassWithDefaultConstructor)
25
+ end
26
+
27
+ it "constructs from a YAML application context definition string" do
28
+ bean_factory = Fabrique::YamlBeanFactory.new(yaml_context_string)
29
+ expect(bean_factory.get_bean('simple_object')).to be_a(Fabrique::Test::Fixtures::Constructors::ClassWithDefaultConstructor)
30
+ end
31
+
32
+ end
metadata CHANGED
@@ -1,85 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fabrique
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sheldon Hearn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-13 00:00:00.000000000 Z
11
+ date: 2016-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: liquid
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: '3.0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ~>
25
- - !ruby/object:Gem::Version
26
- version: '3.0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - ~>
17
+ - - "~>"
32
18
  - !ruby/object:Gem::Version
33
19
  version: '1.7'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - ~>
24
+ - - "~>"
39
25
  - !ruby/object:Gem::Version
40
26
  version: '1.7'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - ~>
31
+ - - "~>"
46
32
  - !ruby/object:Gem::Version
47
33
  version: '10.0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ~>
38
+ - - "~>"
53
39
  - !ruby/object:Gem::Version
54
40
  version: '10.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rspec
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - ~>
45
+ - - "~>"
60
46
  - !ruby/object:Gem::Version
61
47
  version: '3.2'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - ~>
52
+ - - "~>"
67
53
  - !ruby/object:Gem::Version
68
54
  version: '3.2'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: cucumber
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - ~>
59
+ - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: '1.3'
61
+ version: '2.0'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - ~>
66
+ - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: '1.3'
68
+ version: '2.0'
83
69
  description: Factory support library for adapting existing modules for injection as
84
70
  dependencies
85
71
  email:
@@ -88,11 +74,11 @@ executables: []
88
74
  extensions: []
89
75
  extra_rdoc_files: []
90
76
  files:
91
- - .gitignore
92
- - .rspec
93
- - .ruby-gemset
94
- - .ruby-version
95
- - .travis.yml
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".ruby-gemset"
80
+ - ".ruby-version"
81
+ - ".travis.yml"
96
82
  - Gemfile
97
83
  - Guardfile
98
84
  - LICENSE.txt
@@ -114,6 +100,7 @@ files:
114
100
  - lib/fabrique/bean_definition.rb
115
101
  - lib/fabrique/bean_definition_registry.rb
116
102
  - lib/fabrique/bean_factory.rb
103
+ - lib/fabrique/bean_property_reference.rb
117
104
  - lib/fabrique/bean_reference.rb
118
105
  - lib/fabrique/construction/as_is.rb
119
106
  - lib/fabrique/construction/builder_method.rb
@@ -140,6 +127,7 @@ files:
140
127
  - spec/fabrique/construction/properties_hash_spec.rb
141
128
  - spec/fabrique/constructor/identity_spec.rb
142
129
  - spec/fabrique/plugin_registry_spec.rb
130
+ - spec/fabrique/yaml_bean_factory_spec.rb
143
131
  - spec/fabrique_spec.rb
144
132
  - spec/spec_helper.rb
145
133
  homepage: https://github.com/starjuice/fabrique
@@ -152,17 +140,17 @@ require_paths:
152
140
  - lib
153
141
  required_ruby_version: !ruby/object:Gem::Requirement
154
142
  requirements:
155
- - - '>='
143
+ - - ">="
156
144
  - !ruby/object:Gem::Version
157
145
  version: '2.0'
158
146
  required_rubygems_version: !ruby/object:Gem::Requirement
159
147
  requirements:
160
- - - '>='
148
+ - - ">="
161
149
  - !ruby/object:Gem::Version
162
150
  version: '0'
163
151
  requirements: []
164
152
  rubyforge_project:
165
- rubygems_version: 2.4.6
153
+ rubygems_version: 2.5.1
166
154
  signing_key:
167
155
  specification_version: 4
168
156
  summary: Factory support library
@@ -181,5 +169,6 @@ test_files:
181
169
  - spec/fabrique/construction/properties_hash_spec.rb
182
170
  - spec/fabrique/constructor/identity_spec.rb
183
171
  - spec/fabrique/plugin_registry_spec.rb
172
+ - spec/fabrique/yaml_bean_factory_spec.rb
184
173
  - spec/fabrique_spec.rb
185
174
  - spec/spec_helper.rb