configurations 1.4.0 → 2.0.0.pre

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
- ---
2
- SHA1:
3
- metadata.gz: 2589e2f8682eac2622c16993dc89aab75f8d0835
4
- data.tar.gz: 95c59f8d0f29f2c7cddb2a10dfbfdfa601c11989
5
- SHA512:
6
- metadata.gz: 7d59363609ad7d37bb56a596de502e59eaddbd60dc6e9138bd7f09650e768e6c61f8d22d81191dadf620ac0ce6fe40a2dcaac8ccd6d2971b1f0d6178a7cebc42
7
- data.tar.gz: 45603cd9f38b71a9e1086c2b0486f29f089377de972c2b96dbaa7f57d819291f9c677104d8b4b5883b27c5aaff31e2c22031499c54a5b9c05a2ee0647ec1dff3
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e4dac5ba9d58bb68f5ff84dbd03433a9015f976a
4
+ data.tar.gz: 7ba636f43c643628e1281c2382dc73c4ee4b4a97
5
+ SHA512:
6
+ metadata.gz: e2813ce78bbd73297da31cf753832ae05e058bb5d75cdab01a73171302c58c7931979305f4d2dd267e7ab978573134d589ef57a72e6f75887221f791d961dc0f
7
+ data.tar.gz: 4b102d91d228b20f77097858c6753bd59e880cf060540a4115a5b3452d3bc930ad12804bb77f6fac25c3741cb67ce373c153e29524235709c5229d5b571acd57
data/README.md CHANGED
@@ -10,7 +10,7 @@ Configurations provides a unified approach to do configurations using the `MyGem
10
10
 
11
11
  or with Bundler
12
12
 
13
- `gem 'configurations', '~> 1.4.0'`
13
+ `gem 'configurations', '~> 2.0.0.pre'`
14
14
 
15
15
  Configurations uses [Semver 2.0](http://semver.org/)
16
16
 
@@ -55,6 +55,23 @@ MyGem.configuration.class #=> 'oooh wow'
55
55
  MyGem.configuration.foo.bar.baz #=> 'fizz'
56
56
  ```
57
57
 
58
+ Undefined properties on an arbitrary configuration will return `nil`
59
+
60
+ ```
61
+ MyGem.configuration.not_set #=> nil
62
+ ```
63
+
64
+ If you want to define the behaviour for not set properties yourself, use `not_configured`.
65
+
66
+ ```
67
+ module MyGem
68
+ not_configured do |prop|
69
+ raise NoMethodError, "#{prop} must be configured"
70
+ end
71
+ end
72
+ ```
73
+
74
+
58
75
  ### Second way: Restricted Configuration
59
76
 
60
77
  If you just want some properties to be configurable, consider this option
@@ -87,6 +104,22 @@ MyGem.configuration.foo #=> 'FOO'
87
104
  MyGem.configuration.bar.baz #=> 'FIZZ'
88
105
  ```
89
106
 
107
+ Not configured properties on a restricted configuration will raise `NoMethodError`
108
+
109
+ ```
110
+ MyGem.configuration.not_set #=> <#NoMethodError>
111
+ ```
112
+
113
+ If you want to define the behaviour for not set properties yourself, use `not_configured`. This will only affect properties set to configurable. All not configurable properties will raise `NoMethodError`.
114
+
115
+ ```
116
+ module MyGem
117
+ not_configured do |prop|
118
+ warn :not_configured, "Please configure #{prop} or live in danger"
119
+ end
120
+ end
121
+ ```
122
+
90
123
  ### Third way: Type Restricted Configuration
91
124
 
92
125
  If you want to make sure your configurations only accept one type, consider this option
@@ -121,18 +154,18 @@ module MyGem
121
154
  include Configurations
122
155
  configurable :foo do |value|
123
156
 
124
- # The return value is what gets assigned, unless it is nil,
125
- # in which case the original value persists
126
- #
127
- value + ' ooooh my'
157
+ # The return value is what gets assigned, unless it is nil,
158
+ # in which case the original value persists
159
+ #
160
+ value + ' ooooh my'
128
161
  end
129
162
  configurable String, bar: :baz do |value|
130
163
 
131
- # value is guaranteed to be a string at this point
132
- #
133
- unless %w(bi ba bu).include?(value)
134
- raise ArgumentError, 'baz needs to be one of bi, ba, bu'
135
- end
164
+ # value is guaranteed to be a string at this point
165
+ #
166
+ unless %w(bi ba bu).include?(value)
167
+ raise ArgumentError, 'baz needs to be one of bi, ba, bu'
168
+ end
136
169
  end
137
170
  end
138
171
  ```
@@ -166,7 +199,7 @@ module MyGem
166
199
  include Configurations
167
200
  configurable :foo, :bar
168
201
  configuration_method :foobar do |arg|
169
- foo + bar + arg
202
+ foo + bar + arg
170
203
  end
171
204
  end
172
205
  ```
@@ -193,7 +226,7 @@ MyGem.configuration.foobar('ARG') #=> 'FOOBARARG'
193
226
  module MyGem
194
227
  include Configurations
195
228
  configuration_defaults do |c|
196
- c.foo.bar.baz = 'BAR'
229
+ c.foo.bar.baz = 'BAR'
197
230
  end
198
231
  end
199
232
  ```
@@ -12,5 +12,5 @@ module Configurations
12
12
 
13
13
  # Version number of Configurations
14
14
  #
15
- VERSION = '1.4.0'
15
+ VERSION = '2.0.0.pre'
16
16
  end
@@ -28,7 +28,13 @@ module Configurations
28
28
  #
29
29
  def configure(&block)
30
30
  raise ArgumentError, 'can not configure without a block' unless block_given?
31
- @configuration = #{self}::Configuration.new(@configuration_defaults, @configurable, &block)
31
+ @configuration = #{base.name}::Configuration.new(
32
+ defaults: @configuration_defaults,
33
+ methods: @configuration_methods,
34
+ configurable: @configurable,
35
+ not_configured: @not_configured_callback,
36
+ &block
37
+ )
32
38
  end
33
39
  end
34
40
  EOF
@@ -85,11 +91,19 @@ module Configurations
85
91
  # end
86
92
  #
87
93
  def configuration_method(method, &block)
88
- raise ArgumentError, "#{method} can not be both a configurable property and a configuration method" if configurable?(method)
94
+ raise ArgumentError, "can not be both a configurable property and a configuration method" if configurable?(method)
95
+ @configuration_methods ||= {}
96
+ @configuration_methods.merge! method => block
97
+ end
89
98
 
90
- Configuration.class_eval do
91
- define_method method, &block
92
- end
99
+ # not_configured defines the behaviour when a property has not been configured
100
+ # This can be useful for presence validations of certain properties
101
+ # or behaviour for undefined properties deviating from the original behaviour
102
+ # @param [Proc] block the block to evaluate
103
+ # @yield [Symbol] the property that has not been configured
104
+ #
105
+ def not_configured(&block)
106
+ @not_configured_callback = block
93
107
  end
94
108
 
95
109
  private
@@ -3,7 +3,6 @@ module Configurations
3
3
  # Configuration is a blank object in order to allow configuration of various properties including keywords
4
4
  #
5
5
  class Configuration < BasicObject
6
-
7
6
  # 1.9 does not allow for method rebinding in another scope
8
7
  #
9
8
  if ::RUBY_VERSION < '2.0.0'
@@ -33,25 +32,32 @@ module Configurations
33
32
  # Installs the inspect method from Kernel
34
33
  #
35
34
  install_kernel_method(:inspect)
35
+
36
36
  end
37
37
 
38
38
  # Initialize a new configuration
39
- # @param [Proc] configuration_defaults A proc yielding to a default configuration
40
- # @param [Hash] configurable a hash of configurable properties and their asserted types if given
39
+ # @param [Hash] options The options to initialize a configuration with
40
+ # @option options [Hash] configurable a hash of configurable properties and their asserted types if given
41
+ # @option options [Hash] methods a hash of method names pointing to procs
42
+ # @option options [Proc] not_configured a proc to evaluate for not_configured properties
41
43
  # @param [Proc] block a block to configure this configuration with
44
+ # @yield [HostModule::Configuration] a configuration
42
45
  # @return [HostModule::Configuration] a configuration
43
46
  #
44
- def initialize(configuration_defaults, configurable, &block)
45
- @_writeable = true
46
- @configurable = configurable
47
+ def initialize(options={}, &block)
48
+ @_configurable = options[:configurable]
49
+ @_methods = options[:methods]
50
+ @_not_configured = options[:not_configured]
51
+
52
+ @_writeable = true
47
53
  @configuration = _configuration_hash
48
54
 
49
55
  _evaluate_configurable!
50
56
 
51
- self.instance_eval(&configuration_defaults) if configuration_defaults
57
+ instance_eval(&options[:defaults]) if options[:defaults]
52
58
 
53
59
  if block
54
- self.instance_eval(&block)
60
+ instance_eval(&block)
55
61
  self._writeable = false
56
62
  end
57
63
  end
@@ -64,8 +70,12 @@ module Configurations
64
70
 
65
71
  if _respond_to_writer?(method)
66
72
  _assign!(property, value)
67
- elsif _respond_to_property?(method)
73
+ elsif _respond_to_property_for_write?(method)
68
74
  @configuration[method]
75
+ elsif _respond_to_property_for_read?(method)
76
+ @configuration.fetch(method, &_not_configured_callback)
77
+ elsif _has_configuration_method?(method)
78
+ _exec_configuration_method!(method, *args, &block)
69
79
  elsif _can_delegate_to_kernel?(method)
70
80
  ::Kernel.send(method, *args, &block)
71
81
  else
@@ -76,7 +86,7 @@ module Configurations
76
86
  # Respond to missing according to the method_missing implementation
77
87
  #
78
88
  def respond_to?(method, include_private = false)
79
- _respond_to_writer?(method) or _respond_to_property?(method) or _can_delegate_to_kernel?(method) or super
89
+ _respond_to_writer?(method) or _respond_to_property_for_write?(method) or _respond_to_property_for_read?(method) or _can_delegate_to_kernel?(method) or !!super
80
90
  end
81
91
 
82
92
  # Set the configuration to writeable or read only. Access to writer methods is only allowed within the
@@ -122,19 +132,19 @@ module Configurations
122
132
  # @return [Boolean] whether the given property is configurable
123
133
  #
124
134
  def _configurable?(property)
125
- _arbitrarily_configurable? or @configurable.has_key?(property)
135
+ _arbitrarily_configurable? or @_configurable.has_key?(property)
126
136
  end
127
137
 
128
138
 
129
139
  # @return [Boolean] whether this configuration is arbitrarily configurable
130
140
  #
131
141
  def _arbitrarily_configurable?
132
- @configurable.nil? or @configurable.empty?
142
+ @_configurable.nil? or @_configurable.empty?
133
143
  end
134
144
 
135
145
  # @return [Hash] the configurations configurable hash
136
146
  def _configurable
137
- @configurable
147
+ @_configurable
138
148
  end
139
149
 
140
150
  private
@@ -143,31 +153,50 @@ module Configurations
143
153
  # @return [Boolean] whether the given property has been configured
144
154
  #
145
155
  def _configured?(property)
146
- @configuration.has_key?(property)
156
+ @configuration.has_key?(property) or _not_configured_callback? or _arbitrarily_configurable?
147
157
  end
148
158
 
149
159
  # @return [Hash] A configuration hash instantiating subhashes if the key is configurable
150
160
  #
151
161
  def _configuration_hash
152
162
  ::Hash.new do |h, k|
153
- h[k] = Configuration.new(nil, @configurable) if _configurable?(k)
163
+ h[k] = Configuration.new(configurable: @_configurable, not_configured: @_not_configured) if _configurable?(k)
154
164
  end
155
165
  end
156
166
 
167
+ # @return [Proc] The not_configured callback
168
+ #
169
+ def _not_configured_callback
170
+ @_not_configured || ::Proc.new { |key| nil }
171
+ end
172
+
173
+ # @return [Boolean] whether the not configured callback has been configured
174
+ #
175
+ def _not_configured_callback?
176
+ !!@_not_configured
177
+ end
178
+
157
179
  # Evaluates configurable properties and passes eventual hashes down to subconfigurations
158
180
  #
159
181
  def _evaluate_configurable!
160
182
  return if _arbitrarily_configurable?
161
183
 
162
- @configurable.each do |k, assertion|
184
+ @_configurable.each do |k, assertion|
163
185
  if k.is_a?(::Hash)
164
186
  k.each do |property, nested|
165
- @configuration[property] = Configuration.new(nil, _configurable_hash(property, nested, assertion))
187
+ @configuration[property] = Configuration.new(configurable: _configurable_hash(property, nested, assertion), not_configured: _not_configured_callback)
166
188
  end
167
189
  end
168
190
  end
169
191
  end
170
192
 
193
+ # Executes a configuration method
194
+ #
195
+ def _exec_configuration_method!(method, *args, &block)
196
+ args << block #rbx complains if block is separate in the arguments list
197
+ instance_exec(*args, &@_methods[method])
198
+ end
199
+
171
200
  # @param [Symbol, Hash, Array] property configurable properties, either single or nested
172
201
  # @param [Symbol, Hash, Array] value configurable properties, either single or nested
173
202
  # @param [Hash] assertion assertion if any
@@ -200,7 +229,7 @@ module Configurations
200
229
  def _assert_type!(property, value)
201
230
  return unless _evaluable?(property, :type)
202
231
 
203
- assertion = @configurable[property][:type]
232
+ assertion = @_configurable[property][:type]
204
233
  ::Kernel.raise ConfigurationError, "Expected #{property} to be configured with #{assertion}, but got #{value.class.inspect}", caller unless value.is_a?(assertion)
205
234
  end
206
235
 
@@ -211,7 +240,7 @@ module Configurations
211
240
  def _evaluate_block!(property, value)
212
241
  return value unless _evaluable?(property, :block)
213
242
 
214
- evaluation = @configurable[property][:block]
243
+ evaluation = @_configurable[property][:block]
215
244
  evaluation.call(value)
216
245
  end
217
246
 
@@ -220,7 +249,7 @@ module Configurations
220
249
  # @return [Boolean] whether the given property is assertable
221
250
  #
222
251
  def _evaluable?(property, evaluation)
223
- @configurable and @configurable.has_key?(property) and @configurable[property].is_a?(::Hash) and @configurable[property].has_key?(evaluation)
252
+ @_configurable and @_configurable.has_key?(property) and @_configurable[property].is_a?(::Hash) and @_configurable[property].has_key?(evaluation)
224
253
  end
225
254
 
226
255
  # @param [Symbol] property The property to test for
@@ -237,6 +266,13 @@ module Configurations
237
266
  method.to_s.end_with?('=')
238
267
  end
239
268
 
269
+ # @param [Symbol] method the method to test for existence
270
+ # @return [Boolean] whether the method exists as a configuration method
271
+ #
272
+ def _has_configuration_method?(method)
273
+ @_methods and @_methods.has_key?(method)
274
+ end
275
+
240
276
  # @param [Symbol] method the method to test for
241
277
  # @return [Boolean] whether the configuration responds to the given method writer
242
278
  #
@@ -245,10 +281,17 @@ module Configurations
245
281
  end
246
282
 
247
283
  # @param [Symbol] method the method to test for
248
- # @return [Boolean] whether the configuration responds to the given property as a method
284
+ # @return [Boolean] whether the configuration responds to the given property as a method during readable state
285
+ #
286
+ def _respond_to_property_for_read?(method)
287
+ not _is_writer?(method) and _configured?(method)
288
+ end
289
+
290
+ # @param [Symbol] method the method to test for
291
+ # @return [Boolean] whether the configuration responds to the given property as a method during writeable state
249
292
  #
250
- def _respond_to_property?(method)
251
- not _is_writer?(method) and (@_writeable or _configured?(method))
293
+ def _respond_to_property_for_write?(method)
294
+ not _is_writer?(method) and @_writeable
252
295
  end
253
296
 
254
297
  # @param [Symbol] method the method to test for
@@ -2,8 +2,8 @@ require 'test_helper'
2
2
 
3
3
  class TestStricterConfigurationWithBlock < Minitest::Test
4
4
 
5
- BlocksConfigurationTestModule = testmodule_for(Configurations)
6
- BlocksConfigurationTestModule.module_eval do
5
+ module BlocksConfigurationTestModule
6
+ include Configurations
7
7
  configurable :property1, :property2 do |value|
8
8
  value.to_s + 'oooh'
9
9
  end
@@ -2,11 +2,8 @@ require 'test_helper'
2
2
 
3
3
  class TestConfiguration < Minitest::Test
4
4
 
5
- ConfigurationTestModule = testmodule_for(Configurations)
6
- ConfigurationDefaultTestModule = testmodule_for(Configurations)
7
- ConfigurationNoDefaultTestModule = testmodule_for(Configurations)
8
-
9
- ConfigurationTestModule.module_eval do
5
+ module ConfigurationTestModule
6
+ include Configurations
10
7
  configuration_defaults do |c|
11
8
  c.uh.this.is.neat = 'NEAT'
12
9
  c.pah = 'PUH'
@@ -15,16 +12,33 @@ class TestConfiguration < Minitest::Test
15
12
  end
16
13
  end
17
14
 
18
- ConfigurationDefaultTestModule.module_eval do
15
+ module ConfigurationDefaultTestModule
16
+ include Configurations
19
17
  configuration_defaults do |c|
20
18
  c.set = 'SET'
21
19
  end
22
20
  end
23
21
 
22
+ module ConfigurationNoDefaultTestModule
23
+ include Configurations
24
+ end
25
+
26
+ module ConfigurationNotConfiguredTestModule
27
+ include Configurations
28
+ configuration_defaults do |c|
29
+ c.set.set = 'SET'
30
+ end
31
+
32
+ not_configured do |property|
33
+ raise ArgumentError, "#{property} must be configured"
34
+ end
35
+ end
36
+
24
37
  def setup
25
38
  ConfigurationTestModule.configure do |c|
26
39
  c.basic = 'BASIC'
27
40
  c.class = 'KEY'
41
+ c.puts = 'OH'
28
42
  c.overwriteee = 'YEAH'
29
43
  c.overwrite.this = 'OVERWRITE'
30
44
  c.github.repo = 'github.com/beatrichartz/configurations'
@@ -33,6 +47,8 @@ class TestConfiguration < Minitest::Test
33
47
  end
34
48
 
35
49
  @configuration = ConfigurationTestModule.configuration
50
+ @not_configured_configuration = ConfigurationNotConfiguredTestModule.configuration
51
+ @defaults_configuration = ConfigurationDefaultTestModule.configuration
36
52
  end
37
53
 
38
54
  def test_configuration_is_subclass_of_host_module
@@ -46,6 +62,7 @@ class TestConfiguration < Minitest::Test
46
62
  this: { is: { neat: 'NEAT' } }
47
63
  },
48
64
  pah: 'PUH',
65
+ puts: 'OH',
49
66
  overwrite: {
50
67
  this: 'OVERWRITE'
51
68
  },
@@ -76,7 +93,7 @@ class TestConfiguration < Minitest::Test
76
93
  end
77
94
 
78
95
  def test_defaults_without_configure
79
- assert_equal 'SET', ConfigurationDefaultTestModule.configuration.set
96
+ assert_equal 'SET', @defaults_configuration.set
80
97
  end
81
98
 
82
99
  def test_no_defaults_without_configure
@@ -112,18 +129,34 @@ class TestConfiguration < Minitest::Test
112
129
  assert_equal 'something', @configuration.something.else.entirely.nested.deep.below
113
130
  end
114
131
 
115
- def test_not_callable_with_undefined_property
116
- assert_raises NoMethodError do
117
- @configuration.somethings
132
+ def test_respond_to_with_undefined_property
133
+ assert_equal true, @configuration.respond_to?(:somethings)
134
+ end
135
+
136
+ def test_nil_with_undefined_property
137
+ assert_nil @configuration.somethings
138
+ end
139
+
140
+ def test_overwritten_kernel_method
141
+ assert_equal 'OH', @configuration.puts
142
+ end
143
+
144
+ def test_not_configured_callback
145
+ assert_raises ArgumentError do
146
+ @not_configured_configuration.something
118
147
  end
119
148
  end
120
149
 
121
- def test_method_missing_on_kernel_method
122
- assert_raises StandardError do
123
- @configuration.raise StandardError
150
+ def test_nested_not_configured_callback
151
+ assert_raises ArgumentError do
152
+ @not_configured_configuration.set.something
124
153
  end
125
154
  end
126
155
 
156
+ def test_nested_configured_property_with_not_configured
157
+ assert_equal 'SET', @not_configured_configuration.set.set
158
+ end
159
+
127
160
  def test_respond_to_on_writer_while_writeable
128
161
  ConfigurationTestModule.configure do |c|
129
162
  assert_equal true, c.respond_to?(:pah=)
@@ -135,17 +168,15 @@ class TestConfiguration < Minitest::Test
135
168
  end
136
169
 
137
170
  def test_respond_to_on_kernel_method
138
- assert_equal true, @configuration.respond_to?(:puts)
171
+ assert_equal true, @configuration.respond_to?(:raise)
139
172
  end
140
173
 
141
174
  def test_method_missing_on_non_kernel_method
142
- assert_raises NoMethodError do
143
- @configuration.blabla
144
- end
175
+ assert_nil @configuration.blabla
145
176
  end
146
177
 
147
178
  def test_respond_to_missing_on_non_kernel_method
148
- assert_equal false, @configuration.respond_to?(:bbaaaaa)
179
+ assert_equal true, @configuration.respond_to?(:bbaaaaa)
149
180
  end
150
181
 
151
182
  end
@@ -2,8 +2,9 @@ require 'test_helper'
2
2
 
3
3
  class TestConfigurationMethods < Minitest::Test
4
4
 
5
- ConfigurationMethodsClassModule = testmodule_for(Configurations)
6
- ConfigurationMethodsClassModule.module_eval do
5
+ module ConfigurationMethodsClassModule
6
+ include Configurations
7
+
7
8
  class MyClass
8
9
  attr_reader :props
9
10
  def initialize(*props)
@@ -27,13 +28,24 @@ class TestConfigurationMethods < Minitest::Test
27
28
  end
28
29
  end
29
30
 
31
+ module ConfigurationNoMethodsClassModule
32
+ include Configurations
33
+
34
+ configurable :property3
35
+ end
36
+
30
37
  def setup
31
38
  ConfigurationMethodsClassModule.configure do |c|
32
39
  c.property1 = :one
33
40
  c.property2 = :two
34
41
  end
35
42
 
43
+ ConfigurationNoMethodsClassModule.configure do |c|
44
+ c.property3 = :three
45
+ end
46
+
36
47
  @configuration = ConfigurationMethodsClassModule.configuration
48
+ @no_method_configuration = ConfigurationNoMethodsClassModule.configuration
37
49
  end
38
50
 
39
51
  def test_configuration_method
@@ -64,4 +76,10 @@ class TestConfigurationMethods < Minitest::Test
64
76
  end
65
77
  end
66
78
 
79
+ def test_configuration_methods_unaffected
80
+ assert_raises NoMethodError do
81
+ @no_method_configuration.method3('ARG')
82
+ end
83
+ end
84
+
67
85
  end
@@ -1,9 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class TestStricterConfiguration < Minitest::Test
4
+ module StrictConfigurationTestModule
5
+ include Configurations
4
6
 
5
- StrictConfigurationTestModule = testmodule_for(Configurations)
6
- StrictConfigurationTestModule.module_eval do
7
7
  configurable :property1, :property2
8
8
  configurable String, :property3
9
9
  configurable Symbol, property4: :property5, property6: [:property7, :property8]
@@ -13,6 +13,16 @@ class TestStricterConfiguration < Minitest::Test
13
13
  configurable Hash, property9: { property10: { property11: :property13 } }
14
14
  end
15
15
 
16
+ module StrictConfigurationTestModuleDefaultsError
17
+ include Configurations
18
+
19
+ configurable :property1, :property2
20
+
21
+ not_configured do |prop|
22
+ raise StandardError, 'Problem here'
23
+ end
24
+ end
25
+
16
26
  def setup
17
27
  StrictConfigurationTestModule.configure do |c|
18
28
  c.property1 = 'BASIC1'
@@ -26,8 +36,12 @@ class TestStricterConfiguration < Minitest::Test
26
36
  c.property9.property10.property11.property12 = %w(here I am)
27
37
  c.property9.property10.property11.property13 = { hi: :bye }
28
38
  end
39
+ StrictConfigurationTestModuleDefaultsError.configure do |c|
40
+ c.property1 = 'BASIC3'
41
+ end
29
42
 
30
43
  @configuration = StrictConfigurationTestModule.configuration
44
+ @configuration_defaults_error = StrictConfigurationTestModuleDefaultsError.configuration
31
45
  end
32
46
 
33
47
  def test_configurable_when_set_configurable
@@ -65,17 +79,17 @@ class TestStricterConfiguration < Minitest::Test
65
79
  property7: :anything,
66
80
  property8: :everything,
67
81
  property14: 555
68
- },
82
+ },
69
83
  property9: {
70
84
  property10: {
71
85
  property11: {
72
- property12: %w(here I am),
86
+ property12: %w(here I am),
73
87
  property13: {
74
88
  hi: :bye
75
89
  }
76
90
  }
77
91
  }
78
- },
92
+ },
79
93
  property1: 'BASIC1',
80
94
  property2: 'BASIC2',
81
95
  property3: 'STRING'
@@ -124,12 +138,26 @@ class TestStricterConfiguration < Minitest::Test
124
138
  end
125
139
  end
126
140
 
141
+ def test_respond_to_with_undefined_property
142
+ assert_equal false, @configuration.respond_to?(:property12)
143
+ end
144
+
127
145
  def test_not_callable_with_undefined_property
128
146
  assert_raises NoMethodError do
129
147
  @configuration.property12
130
148
  end
131
149
  end
132
150
 
151
+ def test_not_configured_callback
152
+ assert_raises StandardError do
153
+ @configuration_defaults_error.property2
154
+ end
155
+ end
156
+
157
+ def test_not_configured_callback_not_triggered_for_configured
158
+ assert_equal 'BASIC3', @configuration_defaults_error.property1
159
+ end
160
+
133
161
  def test_not_configurable_with_undefined_nested_property
134
162
  assert_raises NoMethodError do
135
163
  StrictConfigurationTestModule.configure do |c|
@@ -138,10 +166,8 @@ class TestStricterConfiguration < Minitest::Test
138
166
  end
139
167
  end
140
168
 
141
- def test_not_callable_with_undefined_nested_property
142
- assert_raises NoMethodError do
143
- @configuration.property6.property9
144
- end
169
+ def test_callable_with_undefined_nested_property
170
+ assert_nil @configuration.property6.property9
145
171
  end
146
172
 
147
173
  end
metadata CHANGED
@@ -1,67 +1,57 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: configurations
3
- version: !ruby/object:Gem::Version
4
- version: 1.4.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0.pre
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Beat Richartz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-27 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
11
+
12
+ date: 2014-11-02 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
14
15
  name: minitest
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '5.4'
20
- type: :development
21
16
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '5.4'
27
- - !ruby/object:Gem::Dependency
28
- name: yard
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0.8'
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: "5.4"
34
22
  type: :development
23
+ version_requirements: *id001
24
+ - !ruby/object:Gem::Dependency
25
+ name: yard
35
26
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '0.8'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '10'
27
+ requirement: &id002 !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: "0.8"
48
32
  type: :development
33
+ version_requirements: *id002
34
+ - !ruby/object:Gem::Dependency
35
+ name: rake
49
36
  prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '10'
55
- description: Configurations provides a unified approach to do configurations with
56
- the flexibility to do everything from arbitrary configurations to type asserted
57
- configurations for your gem or any other ruby code.
37
+ requirement: &id003 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: "10"
42
+ type: :development
43
+ version_requirements: *id003
44
+ description: Configurations provides a unified approach to do configurations with the flexibility to do everything from arbitrary configurations to type asserted configurations for your gem or any other ruby code.
58
45
  email: attr_accessor@gmail.com
59
46
  executables: []
47
+
60
48
  extensions: []
49
+
61
50
  extra_rdoc_files: []
62
- files:
63
- - ".gitignore"
64
- - ".travis.yml"
51
+
52
+ files:
53
+ - .gitignore
54
+ - .travis.yml
65
55
  - Gemfile
66
56
  - License.txt
67
57
  - README.md
@@ -78,31 +68,33 @@ files:
78
68
  - test/support/testmodules.rb
79
69
  - test/test_helper.rb
80
70
  homepage: http://github.com/beatrichartz/configurations
81
- licenses:
71
+ licenses:
82
72
  - MIT
83
73
  metadata: {}
74
+
84
75
  post_install_message:
85
76
  rdoc_options: []
86
- require_paths:
77
+
78
+ require_paths:
87
79
  - lib
88
- required_ruby_version: !ruby/object:Gem::Requirement
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: '0'
93
- required_rubygems_version: !ruby/object:Gem::Requirement
94
- requirements:
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
95
82
  - - ">="
96
- - !ruby/object:Gem::Version
97
- version: '0'
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.3.1
98
90
  requirements: []
91
+
99
92
  rubyforge_project:
100
93
  rubygems_version: 2.2.2
101
94
  signing_key:
102
95
  specification_version: 4
103
- summary: Configurations with a configure block from arbitrary to type-restricted for
104
- your gem or other ruby code.
105
- test_files:
96
+ summary: Configurations with a configure block from arbitrary to type-restricted for your gem or other ruby code.
97
+ test_files:
106
98
  - test/configurations/test_configurable_with_blocks_configuration.rb
107
99
  - test/configurations/test_configuration.rb
108
100
  - test/configurations/test_configuration_methods.rb