configurations 1.3.4 → 1.3.5

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: 877c1c2cfb4af009d16fa6a91452fc214e846b13
4
- data.tar.gz: d87d69a891eb5a54160ad0a4424f86ec0b927a0e
3
+ metadata.gz: 91fb60bb5d9360f44127b6fe04e9ee5a44fc8cc4
4
+ data.tar.gz: f6954851568a3a8dc02abb41867391ac9e83133d
5
5
  SHA512:
6
- metadata.gz: 35339199e77ff86125b9624a52033eed03592fe599c48e067cb6215cb2899541c437f1b62768772a8b53cb5367bd7167651bd22139766e7386ea1cd576ae2f90
7
- data.tar.gz: 3f6c9f7c82910f9d766345a4e7f2637f6aaa6cb3a6d9d5a235cb11beee5ba0d0bace240765228357589470c2abf77400243f73ac2176ec46e35870d5ef34d562
6
+ metadata.gz: e5e0337c82a36aecf0716baaad50605372f31048ae57cfcea910a5946e6e7a04b6345ce08b851fe08c9721b80ac958f9b15c94d7573a1f4b027ec3f0be7cafb9
7
+ data.tar.gz: 513d1a3804e612121dde365f0966edc22120b6d5ce7f17c8d173c14751d9de0967934111a05922afdf86770b16b1853b650b970bac3ce2f299bf83ace3c32ca3
data/README.md CHANGED
@@ -206,7 +206,7 @@ MyGem.configuration.to_h #=> a Hash
206
206
 
207
207
  ### Some caveats
208
208
 
209
- The `to_h` from above is along with `method_missing`, `object_id` and `initialize` the only purposely defined method which you can not overwrite with a configuration value.
209
+ The `to_h` from above is along with `method_missing`, `object_id` and `initialize` the only purposely defined API method which you can not overwrite with a configuration value.
210
210
  Apart from these methods, you should be able to set pretty much any property name you like. `Configuration` inherits from `BasicObject`, so even `Kernel` and `Object` method names are available.
211
211
 
212
212
  ## Contributing
@@ -12,5 +12,5 @@ module Configurations
12
12
 
13
13
  # Version number of Configurations
14
14
  #
15
- VERSION = '1.3.4'
15
+ VERSION = '1.3.5'
16
16
  end
@@ -61,11 +61,11 @@ module Configurations
61
61
  property = method.to_s[0..-2].to_sym
62
62
  value = args.first
63
63
 
64
- if _is_writer?(method) && @_writeable && _configurable?(property)
64
+ if _respond_to_writer?(method)
65
65
  _assign!(property, value)
66
- elsif !_is_writer?(method) && @_writeable || _configured?(method)
66
+ elsif _respond_to_property?(method)
67
67
  @configuration[method]
68
- elsif ::Kernel.respond_to?(method, true)
68
+ elsif _can_delegate_to_kernel?(method)
69
69
  ::Kernel.send(method, *args, &block)
70
70
  else
71
71
  super
@@ -74,10 +74,8 @@ module Configurations
74
74
 
75
75
  # Respond to missing according to the method_missing implementation
76
76
  #
77
- def respond_to_missing?(method, include_private = false)
78
- (_is_writer?(method) && @_writeable && _configurable?(property)) ||
79
- (!_is_writer?(method) && @_writeable || _configured?(method)) ||
80
- ::Kernel.respond_to?(method, include_private) || super
77
+ def respond_to?(method, include_private = false)
78
+ _respond_to_writer?(method) or _respond_to_property?(method) or _can_delegate_to_kernel?(method) or super
81
79
  end
82
80
 
83
81
  # Set the configuration to writeable or read only. Access to writer methods is only allowed within the
@@ -214,5 +212,33 @@ module Configurations
214
212
  method.to_s.end_with?('=')
215
213
  end
216
214
 
215
+ # @param [Symbol] method the method to test for
216
+ # @return [Boolean] whether the configuration responds to the given method writer
217
+ #
218
+ def _respond_to_writer?(method)
219
+ _is_writer?(method) and @_writeable and _configurable?(_property_from_writer(method))
220
+ end
221
+
222
+ # @param [Symbol] method the method to test for
223
+ # @return [Boolean] whether the configuration responds to the given property as a method
224
+ #
225
+ def _respond_to_property?(method)
226
+ not _is_writer?(method) and (@_writeable or _configured?(method))
227
+ end
228
+
229
+ # @param [Symbol] method the method to test for
230
+ # @return [Boolean] whether the configuration can delegate the given method to Kernel
231
+ #
232
+ def _can_delegate_to_kernel?(method)
233
+ ::Kernel.respond_to?(method, true)
234
+ end
235
+
236
+ # @param [Symbol] method the writer method to turn into a property
237
+ # @return [Symbol] the property derived from the writer method
238
+ #
239
+ def _property_from_writer(method)
240
+ method.to_s[0..-2].to_sym
241
+ end
242
+
217
243
  end
218
244
  end
@@ -120,7 +120,17 @@ class TestConfiguration < Minitest::Test
120
120
  end
121
121
  end
122
122
 
123
- def test_respond_to_missing_on_kernel_method
123
+ def test_respond_to_on_writer_while_writeable
124
+ ConfigurationTestModule.configure do |c|
125
+ assert_equal true, c.respond_to?(:pah=)
126
+ end
127
+ end
128
+
129
+ def test_respond_to_on_writer_when_not_writeable
130
+ assert_equal false, @configuration.respond_to?(:pah=)
131
+ end
132
+
133
+ def test_respond_to_on_kernel_method
124
134
  assert_equal true, @configuration.respond_to?(:puts)
125
135
  end
126
136
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configurations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beat Richartz