configurations 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/configurations.rb +1 -1
- data/lib/configurations/configurable.rb +5 -1
- data/lib/configurations/configuration.rb +1 -1
- data/test/configurations/test_configuration.rb +24 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 039597b55adc73ff8cddc05edd7c199f5f2c252f
|
4
|
+
data.tar.gz: 1dec69ab7582283ab60f950dc3caa96e92ff2b95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7a927942a4bce9f187a1f491f9469ac898cc62e2687c3b2111163d6b8b665ebaea70767f52fabcdb2e11c1544bc005168610317632ecabe8211373c993897d3
|
7
|
+
data.tar.gz: 97ae55c4e7c2ccae76aab97aa75c912c4b79bbf4a5fc7ebdb752b7150d9b0be821598fc9f060f484e7b456a1a153072a5a5672260c2ca96548d1c2789c6ca89e
|
data/README.md
CHANGED
@@ -140,13 +140,13 @@ MyGem.configuration.to_h #=> a Hash
|
|
140
140
|
### Some caveats
|
141
141
|
|
142
142
|
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.
|
143
|
-
Apart from these methods, you should be able to set pretty much any property name you like. `Configuration` inherits from `BasicObject`, so even
|
143
|
+
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.
|
144
144
|
|
145
145
|
## Contributing
|
146
146
|
|
147
147
|
YES!
|
148
148
|
|
149
|
-
Let's make this awesome. Write tests for your added stuff, bonus points for feature branches. If you don't have
|
149
|
+
Let's make this awesome. Write tests for your added stuff, bonus points for feature branches. If you don't have the time to write a fix, raise an issue.
|
150
150
|
|
151
151
|
### Copyright
|
152
152
|
|
data/lib/configurations.rb
CHANGED
@@ -20,8 +20,10 @@ module Configurations
|
|
20
20
|
class << self
|
21
21
|
# The central configure method
|
22
22
|
# @params [Proc] block the block to configure host module with
|
23
|
+
# @raise [ArgumentError] error when not given a block
|
23
24
|
#
|
24
25
|
def configure(&block)
|
26
|
+
raise ArgumentError, 'can not configure without a block' unless block_given?
|
25
27
|
@configuration = #{self}::Configuration.new(@configuration_defaults, @configurable, &block)
|
26
28
|
end
|
27
29
|
end
|
@@ -33,7 +35,9 @@ module Configurations
|
|
33
35
|
module ClassMethods
|
34
36
|
# A reader for Configuration
|
35
37
|
#
|
36
|
-
|
38
|
+
def configuration
|
39
|
+
@configuration ||= @configuration_defaults && configure { }
|
40
|
+
end
|
37
41
|
|
38
42
|
# Configuration defaults can be used to set the defaults of any Configuration
|
39
43
|
# @param [Proc] block setting the default values of the configuration
|
@@ -60,7 +60,7 @@ module Configurations
|
|
60
60
|
def method_missing(method, *args, &block)
|
61
61
|
property = method.to_s[0..-2].to_sym
|
62
62
|
|
63
|
-
if _is_writer?(method) && _configurable?(property)
|
63
|
+
if _is_writer?(method) && @_writeable && _configurable?(property)
|
64
64
|
_assert_type!(property, args.first)
|
65
65
|
@configuration[property] = args.first
|
66
66
|
elsif !_is_writer?(method) && @_writeable || _configured?(method)
|
@@ -3,6 +3,9 @@ require 'test_helper'
|
|
3
3
|
class TestConfiguration < Minitest::Test
|
4
4
|
|
5
5
|
ConfigurationTestModule = testmodule_for(Configurations)
|
6
|
+
ConfigurationDefaultTestModule = testmodule_for(Configurations)
|
7
|
+
ConfigurationNoDefaultTestModule = testmodule_for(Configurations)
|
8
|
+
|
6
9
|
ConfigurationTestModule.module_eval do
|
7
10
|
configuration_defaults do |c|
|
8
11
|
c.uh.this.is.neat = 'NEAT'
|
@@ -11,6 +14,13 @@ class TestConfiguration < Minitest::Test
|
|
11
14
|
c.overwriteee = 'BLA'
|
12
15
|
end
|
13
16
|
end
|
17
|
+
|
18
|
+
ConfigurationDefaultTestModule.module_eval do
|
19
|
+
configuration_defaults do |c|
|
20
|
+
c.set = 'SET'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
14
24
|
def setup
|
15
25
|
ConfigurationTestModule.configure do |c|
|
16
26
|
c.basic = 'BASIC'
|
@@ -51,10 +61,24 @@ class TestConfiguration < Minitest::Test
|
|
51
61
|
}, @configuration.to_h)
|
52
62
|
end
|
53
63
|
|
64
|
+
def test_not_configurable_unless_block_given
|
65
|
+
assert_raises ArgumentError do
|
66
|
+
ConfigurationTestModule.configure
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
54
70
|
def test_defaults
|
55
71
|
assert_equal 'PUH', @configuration.pah
|
56
72
|
end
|
57
73
|
|
74
|
+
def test_defaults_without_configure
|
75
|
+
assert_equal 'SET', ConfigurationDefaultTestModule.configuration.set
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_no_defaults_without_configure
|
79
|
+
assert_nil ConfigurationNoDefaultTestModule.configuration
|
80
|
+
end
|
81
|
+
|
58
82
|
def test_defaults_overwrite
|
59
83
|
assert_equal 'YEAH', @configuration.overwriteee
|
60
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configurations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Beat Richartz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|