fabrique 0.3.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/Gemfile +4 -0
  4. data/README.md +2 -155
  5. data/fabrique.gemspec +3 -3
  6. data/features/bean_factory.feature +194 -3
  7. data/features/step_definitions/bean_factory_steps.rb +41 -3
  8. data/features/support/fabrique.rb +1 -0
  9. data/fixtures/local_only/.gitignore +9 -0
  10. data/fixtures/local_only/Gemfile +4 -0
  11. data/fixtures/local_only/README.md +36 -0
  12. data/fixtures/local_only/Rakefile +2 -0
  13. data/fixtures/local_only/bin/console +14 -0
  14. data/fixtures/local_only/bin/setup +8 -0
  15. data/fixtures/local_only/lib/local_only/version.rb +3 -0
  16. data/fixtures/local_only/lib/local_only.rb +7 -0
  17. data/fixtures/local_only/local_only.gemspec +31 -0
  18. data/fixtures/local_only-0.1.0.gem +0 -0
  19. data/fixtures/sample/.gitignore +9 -0
  20. data/fixtures/sample/Gemfile +4 -0
  21. data/fixtures/sample/README.md +36 -0
  22. data/fixtures/sample/Rakefile +2 -0
  23. data/fixtures/sample/bin/console +14 -0
  24. data/fixtures/sample/bin/setup +8 -0
  25. data/fixtures/sample/lib/sample/version.rb +3 -0
  26. data/fixtures/sample/lib/sample.rb +9 -0
  27. data/fixtures/sample/sample.gemspec +23 -0
  28. data/lib/fabrique/bean_definition.rb +4 -4
  29. data/lib/fabrique/bean_definition_registry.rb +11 -5
  30. data/lib/fabrique/bean_factory.rb +34 -13
  31. data/lib/fabrique/bean_property_reference.rb +9 -1
  32. data/lib/fabrique/data_bean.rb +62 -0
  33. data/lib/fabrique/gem_definition.rb +15 -0
  34. data/lib/fabrique/gem_dependency_error.rb +6 -0
  35. data/lib/fabrique/gem_loader.rb +25 -0
  36. data/lib/fabrique/test/fixtures/constructors.rb +12 -1
  37. data/lib/fabrique/version.rb +1 -1
  38. data/lib/fabrique.rb +0 -3
  39. data/spec/fabrique/data_bean_spec.rb +129 -0
  40. metadata +32 -38
  41. data/features/plugin_registry.feature +0 -79
  42. data/features/step_definitions/plugin_registry_steps.rb +0 -207
  43. data/lib/fabrique/argument_adaptor/keyword.rb +0 -19
  44. data/lib/fabrique/argument_adaptor/positional.rb +0 -76
  45. data/lib/fabrique/construction/as_is.rb +0 -16
  46. data/lib/fabrique/construction/builder_method.rb +0 -21
  47. data/lib/fabrique/construction/default.rb +0 -17
  48. data/lib/fabrique/construction/keyword_argument.rb +0 -16
  49. data/lib/fabrique/construction/positional_argument.rb +0 -40
  50. data/lib/fabrique/construction/properties_hash.rb +0 -19
  51. data/lib/fabrique/constructor/identity.rb +0 -10
  52. data/lib/fabrique/plugin_registry.rb +0 -56
  53. data/spec/fabrique/argument_adaptor/keyword_spec.rb +0 -50
  54. data/spec/fabrique/argument_adaptor/positional_spec.rb +0 -166
  55. data/spec/fabrique/construction/as_is_spec.rb +0 -23
  56. data/spec/fabrique/construction/builder_method_spec.rb +0 -29
  57. data/spec/fabrique/construction/default_spec.rb +0 -19
  58. data/spec/fabrique/construction/positional_argument_spec.rb +0 -61
  59. data/spec/fabrique/construction/properties_hash_spec.rb +0 -36
  60. data/spec/fabrique/constructor/identity_spec.rb +0 -4
  61. data/spec/fabrique/plugin_registry_spec.rb +0 -78
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fabrique
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 1.0.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: 2016-01-21 00:00:00.000000000 Z
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,8 +66,7 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.0'
69
- description: Factory support library for adapting existing modules for injection as
70
- dependencies
69
+ description: Configuration-based factory for dependency injection
71
70
  email:
72
71
  - sheldonh@starjuice.net
73
72
  executables: []
@@ -90,27 +89,39 @@ files:
90
89
  - docs/multiple_providers.rb
91
90
  - fabrique.gemspec
92
91
  - features/bean_factory.feature
93
- - features/plugin_registry.feature
94
92
  - features/step_definitions/bean_factory_steps.rb
95
- - features/step_definitions/plugin_registry_steps.rb
96
93
  - features/support/byebug.rb
94
+ - features/support/fabrique.rb
95
+ - fixtures/local_only-0.1.0.gem
96
+ - fixtures/local_only/.gitignore
97
+ - fixtures/local_only/Gemfile
98
+ - fixtures/local_only/README.md
99
+ - fixtures/local_only/Rakefile
100
+ - fixtures/local_only/bin/console
101
+ - fixtures/local_only/bin/setup
102
+ - fixtures/local_only/lib/local_only.rb
103
+ - fixtures/local_only/lib/local_only/version.rb
104
+ - fixtures/local_only/local_only.gemspec
105
+ - fixtures/sample/.gitignore
106
+ - fixtures/sample/Gemfile
107
+ - fixtures/sample/README.md
108
+ - fixtures/sample/Rakefile
109
+ - fixtures/sample/bin/console
110
+ - fixtures/sample/bin/setup
111
+ - fixtures/sample/lib/sample.rb
112
+ - fixtures/sample/lib/sample/version.rb
113
+ - fixtures/sample/sample.gemspec
97
114
  - lib/fabrique.rb
98
- - lib/fabrique/argument_adaptor/keyword.rb
99
- - lib/fabrique/argument_adaptor/positional.rb
100
115
  - lib/fabrique/bean_definition.rb
101
116
  - lib/fabrique/bean_definition_registry.rb
102
117
  - lib/fabrique/bean_factory.rb
103
118
  - lib/fabrique/bean_property_reference.rb
104
119
  - lib/fabrique/bean_reference.rb
105
- - lib/fabrique/construction/as_is.rb
106
- - lib/fabrique/construction/builder_method.rb
107
- - lib/fabrique/construction/default.rb
108
- - lib/fabrique/construction/keyword_argument.rb
109
- - lib/fabrique/construction/positional_argument.rb
110
- - lib/fabrique/construction/properties_hash.rb
111
- - lib/fabrique/constructor/identity.rb
112
120
  - lib/fabrique/cyclic_bean_dependency_error.rb
113
- - lib/fabrique/plugin_registry.rb
121
+ - lib/fabrique/data_bean.rb
122
+ - lib/fabrique/gem_definition.rb
123
+ - lib/fabrique/gem_dependency_error.rb
124
+ - lib/fabrique/gem_loader.rb
114
125
  - lib/fabrique/test.rb
115
126
  - lib/fabrique/test/fixtures/constructors.rb
116
127
  - lib/fabrique/test/fixtures/modules.rb
@@ -118,15 +129,7 @@ files:
118
129
  - lib/fabrique/test/fixtures/repository.rb
119
130
  - lib/fabrique/version.rb
120
131
  - lib/fabrique/yaml_bean_factory.rb
121
- - spec/fabrique/argument_adaptor/keyword_spec.rb
122
- - spec/fabrique/argument_adaptor/positional_spec.rb
123
- - spec/fabrique/construction/as_is_spec.rb
124
- - spec/fabrique/construction/builder_method_spec.rb
125
- - spec/fabrique/construction/default_spec.rb
126
- - spec/fabrique/construction/positional_argument_spec.rb
127
- - spec/fabrique/construction/properties_hash_spec.rb
128
- - spec/fabrique/constructor/identity_spec.rb
129
- - spec/fabrique/plugin_registry_spec.rb
132
+ - spec/fabrique/data_bean_spec.rb
130
133
  - spec/fabrique/yaml_bean_factory_spec.rb
131
134
  - spec/fabrique_spec.rb
132
135
  - spec/spec_helper.rb
@@ -142,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
145
  requirements:
143
146
  - - ">="
144
147
  - !ruby/object:Gem::Version
145
- version: '2.0'
148
+ version: '2.1'
146
149
  required_rubygems_version: !ruby/object:Gem::Requirement
147
150
  requirements:
148
151
  - - ">="
@@ -153,22 +156,13 @@ rubyforge_project:
153
156
  rubygems_version: 2.5.1
154
157
  signing_key:
155
158
  specification_version: 4
156
- summary: Factory support library
159
+ summary: Configuration-based factory for dependency injection
157
160
  test_files:
158
161
  - features/bean_factory.feature
159
- - features/plugin_registry.feature
160
162
  - features/step_definitions/bean_factory_steps.rb
161
- - features/step_definitions/plugin_registry_steps.rb
162
163
  - features/support/byebug.rb
163
- - spec/fabrique/argument_adaptor/keyword_spec.rb
164
- - spec/fabrique/argument_adaptor/positional_spec.rb
165
- - spec/fabrique/construction/as_is_spec.rb
166
- - spec/fabrique/construction/builder_method_spec.rb
167
- - spec/fabrique/construction/default_spec.rb
168
- - spec/fabrique/construction/positional_argument_spec.rb
169
- - spec/fabrique/construction/properties_hash_spec.rb
170
- - spec/fabrique/constructor/identity_spec.rb
171
- - spec/fabrique/plugin_registry_spec.rb
164
+ - features/support/fabrique.rb
165
+ - spec/fabrique/data_bean_spec.rb
172
166
  - spec/fabrique/yaml_bean_factory_spec.rb
173
167
  - spec/fabrique_spec.rb
174
168
  - spec/spec_helper.rb
@@ -1,79 +0,0 @@
1
- @plugin_registry
2
- Feature: Plugin registry
3
-
4
- As a developer
5
- I want to register the identity and construction method of different plugins
6
- So that I can decouple their dependants from their means of creation
7
-
8
- Plugins are classes, modules, objects or lambdas that may come from other developers, and so
9
- may have disparate construction methods. A plugin registry allows these differences to be
10
- abstracted, and for them to be created by a known and invariant identity. The identities of
11
- plugins must be defined by the developer of the dependant.
12
-
13
- This does not address the concern of ensuring that multiple plugins offer the same interface.
14
- That concern is dealt with by a contract conformance strategy (e.g. interface through
15
- delegation).
16
-
17
- Most developers will not use a plugin registry directly. Instead, they will use a factory
18
- that implements a conformance strategy. This has the additional benefit of allowing the
19
- developers of plugins to define and register the identities of their plugins.
20
-
21
- Scenario: Multiple plugins
22
-
23
- Given I have a plugin registry
24
- And I have two classes with default constructors
25
- When I register each class into the registry with a unique identity and a default construction method
26
- Then I can acquire instances of each class from the registry by its unique identity
27
-
28
- Scenario Outline: As-is plugin
29
-
30
- Given I have a plugin registry
31
- And I have <article> <entity>, i.e. <code>
32
- When I register the <entity> into the registry with a unique identity and an as-is construction method
33
- Then I get the same <entity> every time I acquire the same identity
34
-
35
- Examples:
36
- | article | entity | code |
37
- | an | object | Object.new |
38
- | a | class | Class |
39
- | a | module | Module |
40
- | a | lambda | -> {} |
41
-
42
- Scenario: Classical plugin with default constructor
43
-
44
- Given I have a plugin registry
45
- And I have a class with a default constructor
46
- When I register the class into the registry with a unique identity and a default construction method
47
- Then I can acquire instances of the class from the registry by its unique identity
48
-
49
- Scenario: Classical plugin with properties hash constructor
50
-
51
- Given I have a plugin registry
52
- And I have a class with a properties hash constructor
53
- When I register the class into the registry with a unique identity and a properties hash construction method
54
- Then I can acquire an instance of the class from the registry by its unique identity, specifying properties with a hash argument
55
-
56
- Scenario: Classical plugin with positional argument constructor
57
-
58
- Given I have a plugin registry
59
- And I have a class with a positional argument constructor
60
- When I register the class into the registry with a unique identity and a positional argument construction method
61
- Then I can acquire an instance of the class from the registry by its unique identity, specifying properties with a hash argument
62
- And the instance has the specified properties
63
-
64
- Scenario: Classical plugin with keyword argument constructor
65
-
66
- Given I have a plugin registry
67
- And I have a class with a keyword argument constructor
68
- When I register the class into the registry with a unique identity and a keyword argument construction method
69
- Then I can acquire an instance of the class from the registry by its unique identity, specifying properties with a hash argument
70
- And the instance has the specified properties
71
-
72
- Scenario: Builder pattern plugin
73
-
74
- Given I have a plugin registry
75
- And I have a class with a builder method
76
- When I register the class into the registry with a unique identity and builder construction method
77
- Then I can acquire an instance of the class from the registry by its unique identity, specifying properties with a hash argument
78
- And the instance has the specified properties
79
-
@@ -1,207 +0,0 @@
1
- require "rspec"
2
- require "fabrique/test"
3
-
4
- class PluginRegistryTestRunner
5
- include RSpec::Matchers
6
- include Fabrique::Test::Fixtures::Constructors
7
-
8
- def initialize(subject_constructor)
9
- @subject_constructor = subject_constructor
10
- end
11
-
12
- def have_plugin_registry
13
- @registry = @subject_constructor.call
14
- end
15
-
16
- def have_class_with_default_constructor
17
- @class = ClassWithDefaultConstructor
18
- end
19
-
20
- def have_two_classes_with_default_constructors
21
- @class1 = ClassWithDefaultConstructor
22
- @class2 = OtherClassWithDefaultConstructor
23
- end
24
-
25
- def have_object(object)
26
- @object = object
27
- end
28
-
29
- def have_class_with_positional_argument_constructor
30
- @class = ClassWithPositionalArgumentConstructor
31
- end
32
-
33
- def have_class_with_properties_hash_constructor
34
- @class = ClassWithPropertiesHashConstructor
35
- end
36
-
37
- def have_class_with_keyword_argument_constructor
38
- @class = ClassWithKeywordArgumentConstructor
39
- end
40
-
41
- def have_class_with_builder_method
42
- @class = ClassWithBuilderMethod
43
- end
44
-
45
- def register_class_with_as_is_constructor
46
- @identity = :my_plugin
47
- @registry.register(@identity, @class, Fabrique::Construction::Default.new)
48
- end
49
-
50
- def register_classes_with_default_constructors
51
- @identity1 = :plugin1
52
- @identity2 = :plugin2
53
- @registry.register(@identity1, @class1, Fabrique::Construction::Default.new)
54
- @registry.register(@identity2, @class2, Fabrique::Construction::Default.new)
55
- end
56
-
57
- def register_object_with_as_is_constructor
58
- @identity = :my_plugin
59
- @registry.register(@identity, @object, Fabrique::Construction::AsIs.new)
60
- end
61
-
62
- def register_class_with_properties_hash_constructor
63
- @identity = :my_plugin
64
- @registry.register(@identity, @class, Fabrique::Construction::PropertiesHash.new)
65
- end
66
-
67
- def register_class_with_positional_argument_constructor
68
- @identity = :my_plugin
69
- @registry.register(@identity, @class, Fabrique::Construction::PositionalArgument.new(:size, :color, :shape))
70
- end
71
-
72
- def register_class_with_keyword_argument_constructor
73
- @identity = :my_plugin
74
- @registry.register(@identity, @class, Fabrique::Construction::KeywordArgument.new)
75
- end
76
-
77
- def register_class_with_builder_method
78
- @identity = :my_plugin
79
- @registry.register(@identity, @class, Fabrique::Construction::BuilderMethod.new(:build) { |builder, properties|
80
- builder.size = properties[:size]
81
- builder.color = properties[:color]
82
- builder.shape = properties[:shape]
83
- })
84
- end
85
-
86
- def can_acquire_instances_of_class
87
- instance1 = @registry.acquire(@identity)
88
- instance2 = @registry.acquire(@identity)
89
- expect(instance1.class).to eql @class
90
- expect(instance2.class).to eql @class
91
- expect(instance1.object_id).to_not eql instance2.object_id
92
- end
93
-
94
- def can_acquire_instances_of_classes
95
- instance1 = @registry.acquire(@identity1)
96
- instance2 = @registry.acquire(@identity2)
97
- expect(instance1.class).to eql @class1
98
- expect(instance2.class).to eql @class2
99
- end
100
-
101
- def can_acquire_same_object_id_every_time
102
- instance1 = @registry.acquire(@identity)
103
- instance2 = @registry.acquire(@identity)
104
- expect(instance1.object_id).to eql @object.object_id
105
- expect(instance2.object_id).to eql @object.object_id
106
- end
107
-
108
- def can_acquire_instance_of_class_with_properties
109
- @instance = @registry.acquire(@identity, size: "large", color: "pink", shape: "cube")
110
- end
111
-
112
- def can_verify_instance_properties
113
- expect(@instance.color).to eql "pink"
114
- expect(@instance.shape).to eql "cube"
115
- expect(@instance.size).to eql "large"
116
- end
117
-
118
- end
119
-
120
- require "fabrique"
121
-
122
- Before do |scenario|
123
- if scenario.tags.any? { |tag| tag.name == "@plugin_registry" }
124
- @test = PluginRegistryTestRunner.new( -> {Fabrique::PluginRegistry.new("Test plugin registry")})
125
- end
126
- end
127
-
128
- Given(/^I have a plugin registry$/) do
129
- @test.have_plugin_registry
130
- end
131
-
132
- Given(/^I have a class with a default constructor$/) do
133
- @test.have_class_with_default_constructor
134
- end
135
-
136
- Given(/^I have two classes with default constructors$/) do
137
- @test.have_two_classes_with_default_constructors
138
- end
139
-
140
- Given(/^I have an? \w+, i\.e\. (.+)$/) do |code|
141
- @test.have_object(eval code)
142
- end
143
-
144
- Given(/^I have a class with a positional argument constructor$/) do
145
- @test.have_class_with_positional_argument_constructor
146
- end
147
-
148
- Given(/^I have a class with a properties hash constructor$/) do
149
- @test.have_class_with_properties_hash_constructor
150
- end
151
-
152
- Given(/^I have a class with a keyword argument constructor$/) do
153
- @test.have_class_with_keyword_argument_constructor
154
- end
155
-
156
- Given(/^I have a class with a builder method$/) do
157
- @test.have_class_with_builder_method
158
- end
159
-
160
- When(/^I register the class into the registry with a unique identity and a default construction method$/) do
161
- @test.register_class_with_as_is_constructor
162
- end
163
-
164
- When(/^I register each class into the registry with a unique identity and a default construction method$/) do
165
- @test.register_classes_with_default_constructors
166
- end
167
-
168
- When(/^I register the \w+ into the registry with a unique identity and an as\-is construction method$/) do
169
- @test.register_object_with_as_is_constructor
170
- end
171
-
172
- When(/^I register the class into the registry with a unique identity and a properties hash construction method$/) do
173
- @test.register_class_with_properties_hash_constructor
174
- end
175
-
176
- When(/^I register the class into the registry with a unique identity and a positional argument construction method$/) do
177
- @test.register_class_with_positional_argument_constructor
178
- end
179
-
180
- When(/^I register the class into the registry with a unique identity and a keyword argument construction method$/) do
181
- @test.register_class_with_keyword_argument_constructor
182
- end
183
-
184
- When(/^I register the class into the registry with a unique identity and builder construction method$/) do
185
- @test.register_class_with_builder_method
186
- end
187
-
188
- Then(/^I can acquire instances of the class from the registry by its unique identity$/) do
189
- @test.can_acquire_instances_of_class
190
- end
191
-
192
- Then(/^I can acquire instances of each class from the registry by its unique identity$/) do
193
- @test.can_acquire_instances_of_classes
194
- end
195
-
196
- Then(/^I get the same \w+ every time I acquire the same identity$/) do
197
- @test.can_acquire_same_object_id_every_time
198
- end
199
-
200
- Then(/^I can acquire an instance of the class from the registry by its unique identity, specifying properties with a hash argument$/) do
201
- @test.can_acquire_instance_of_class_with_properties
202
- end
203
-
204
- Then(/^the instance has the specified properties$/) do
205
- @test.can_verify_instance_properties
206
- end
207
-
@@ -1,19 +0,0 @@
1
- module Fabrique
2
-
3
- module ArgumentAdaptor
4
-
5
- class Keyword
6
-
7
- def adapt(properties = nil)
8
- if properties.nil?
9
- []
10
- else
11
- [properties]
12
- end
13
- end
14
-
15
- end
16
-
17
- end
18
-
19
- end
@@ -1,76 +0,0 @@
1
- module Fabrique
2
-
3
- module ArgumentAdaptor
4
-
5
- # TODO Initialize with the name of the class we're adapting arguments for, for use in error messages
6
- class Positional
7
-
8
- def initialize(*argument_specifiers)
9
- @positional_arguments = argument_specifiers.map { |spec| PositionalArgument.create(spec) }
10
- end
11
-
12
- def adapt(properties = {})
13
- @positional_arguments.map { |argument| argument.pick(properties) }
14
- end
15
-
16
- class PositionalArgument
17
-
18
- class Required
19
- def initialize(arg)
20
- @arg = arg
21
- end
22
-
23
- def pick(properties)
24
- pick_or_do(properties) do
25
- raise ArgumentError, "required argument #{@arg} missing from properties"
26
- end
27
- end
28
-
29
- private
30
-
31
- def pick_or_do(properties, &block)
32
- if properties.include?(@arg)
33
- properties[@arg]
34
- else
35
- block.call
36
- end
37
- end
38
- end
39
-
40
- class Optional < Required
41
- def pick(properties)
42
- pick_or_do(properties) do
43
- raise ArgumentError, "optional argument #{@arg} (with no default) missing from properties"
44
- end
45
- end
46
- end
47
-
48
- class Default < Required
49
- def initialize(arg, default)
50
- @arg, @default = arg, default
51
- end
52
-
53
- def pick(properties)
54
- pick_or_do(properties) { @default }
55
- end
56
- end
57
-
58
- def self.create(specifier)
59
- if specifier.is_a?(Symbol)
60
- Required.new(specifier)
61
- elsif specifier.is_a?(Array) and specifier.size == 1 and specifier[0].is_a?(Symbol)
62
- Optional.new(*specifier)
63
- elsif specifier.is_a?(Array) and specifier.size == 2 and specifier[0].is_a?(Symbol)
64
- Default.new(*specifier)
65
- else
66
- raise ArgumentError.new("invalid argument specifier #{specifier}")
67
- end
68
- end
69
-
70
- end
71
-
72
- end
73
-
74
- end
75
-
76
- end
@@ -1,16 +0,0 @@
1
- module Fabrique
2
-
3
- module Construction
4
-
5
- class AsIs
6
-
7
- def call(type, properties = nil)
8
- raise ArgumentError.new("unexpected properties for as-is construction") unless (properties.nil? or properties.empty?)
9
- type
10
- end
11
-
12
- end
13
-
14
- end
15
-
16
- end
@@ -1,21 +0,0 @@
1
- module Fabrique
2
-
3
- module Construction
4
-
5
- class BuilderMethod
6
-
7
- def initialize(builder_method_name, &block)
8
- @builder_method_name, @builder_runner = builder_method_name, block
9
- end
10
-
11
- def call(type, properties = {})
12
- type.send(@builder_method_name) do |builder|
13
- @builder_runner.call(builder, properties)
14
- end
15
- end
16
-
17
- end
18
-
19
- end
20
-
21
- end
@@ -1,17 +0,0 @@
1
- require_relative "positional_argument"
2
-
3
- module Fabrique
4
-
5
- module Construction
6
-
7
- class Default < PositionalArgument
8
-
9
- def initialize
10
- super()
11
- end
12
-
13
- end
14
-
15
- end
16
-
17
- end
@@ -1,16 +0,0 @@
1
- module Fabrique
2
-
3
- module Construction
4
-
5
- # TODO Derive from PropertiesHash
6
- class KeywordArgument
7
-
8
- def call(type, properties)
9
- type.new(properties)
10
- end
11
-
12
- end
13
-
14
- end
15
-
16
- end
@@ -1,40 +0,0 @@
1
- module Fabrique
2
-
3
- module Construction
4
-
5
- class PositionalArgument
6
-
7
- def initialize(*argument_names)
8
- @argument_names = argument_names
9
- end
10
-
11
- def call(type, properties = nil)
12
- if properties.nil?
13
- type.new
14
- else
15
- type.new(*get_args(properties))
16
- end
17
- end
18
-
19
- private
20
-
21
- def get_args(properties)
22
- @argument_names.inject([]) do |arguments, arg|
23
- if arg.is_a?(Array)
24
- arg.each do |optional_arg|
25
- arguments << properties[optional_arg] if properties.include?(optional_arg)
26
- end
27
- elsif properties.include?(arg)
28
- arguments << properties[arg]
29
- else
30
- raise ArgumentError, "required argument #{arg} missing from properties"
31
- end
32
- arguments
33
- end
34
- end
35
-
36
- end
37
-
38
- end
39
-
40
- end
@@ -1,19 +0,0 @@
1
- module Fabrique
2
-
3
- module Construction
4
-
5
- class PropertiesHash
6
-
7
- def call(type, properties = nil)
8
- if properties.nil?
9
- type.new
10
- else
11
- type.new(properties)
12
- end
13
- end
14
-
15
- end
16
-
17
- end
18
-
19
- end
@@ -1,10 +0,0 @@
1
- module Fabrique
2
-
3
- module Constructor
4
-
5
- class Identity
6
- end
7
-
8
- end
9
-
10
- end