configurations 2.0.0.pre → 2.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 (60) hide show
  1. checksums.yaml +7 -7
  2. data/.travis.yml +4 -2
  3. data/License.txt +1 -1
  4. data/README.md +23 -7
  5. data/Rakefile +1 -1
  6. data/configurations.gemspec +7 -3
  7. data/lib/configurations.rb +8 -4
  8. data/lib/configurations/arbitrary.rb +124 -0
  9. data/lib/configurations/blank_object.rb +60 -0
  10. data/lib/configurations/configurable.rb +153 -42
  11. data/lib/configurations/configuration.rb +96 -213
  12. data/lib/configurations/strict.rb +170 -0
  13. data/test/configurations/arbitrary/test.rb +23 -0
  14. data/test/configurations/arbitrary/test_defaults.rb +5 -0
  15. data/test/configurations/arbitrary/test_hash_methods.rb +11 -0
  16. data/test/configurations/arbitrary/test_methods.rb +5 -0
  17. data/test/configurations/arbitrary/test_not_configured.rb +5 -0
  18. data/test/configurations/arbitrary/test_not_configured_default.rb +5 -0
  19. data/test/configurations/shared/defaults.rb +43 -0
  20. data/test/configurations/shared/hash_methods.rb +40 -0
  21. data/test/configurations/shared/kernel_methods.rb +9 -0
  22. data/test/configurations/shared/methods.rb +31 -0
  23. data/test/configurations/shared/not_configured_callbacks.rb +42 -0
  24. data/test/configurations/shared/not_configured_default_callback.rb +42 -0
  25. data/test/configurations/shared/properties.rb +46 -0
  26. data/test/configurations/shared/properties_outside_block.rb +40 -0
  27. data/test/configurations/shared/strict_hash_methods.rb +43 -0
  28. data/test/configurations/strict/test.rb +20 -0
  29. data/test/configurations/strict/test_defaults.rb +6 -0
  30. data/test/configurations/strict/test_hash_methods.rb +11 -0
  31. data/test/configurations/strict/test_methods.rb +6 -0
  32. data/test/configurations/strict/test_not_configured.rb +6 -0
  33. data/test/configurations/strict/test_not_configured_default.rb +6 -0
  34. data/test/configurations/strict_types/test.rb +18 -0
  35. data/test/configurations/strict_types/test_defaults.rb +6 -0
  36. data/test/configurations/strict_types/test_hash_methods.rb +11 -0
  37. data/test/configurations/strict_types/test_methods.rb +6 -0
  38. data/test/configurations/strict_types/test_not_configured.rb +6 -0
  39. data/test/configurations/strict_types/test_not_configured_default.rb +6 -0
  40. data/test/configurations/strict_types_with_blocks/test.rb +22 -0
  41. data/test/configurations/strict_types_with_blocks/test_defaults.rb +6 -0
  42. data/test/configurations/strict_types_with_blocks/test_hash_methods.rb +14 -0
  43. data/test/configurations/strict_types_with_blocks/test_methods.rb +6 -0
  44. data/test/configurations/strict_types_with_blocks/test_not_configured.rb +6 -0
  45. data/test/configurations/strict_types_with_blocks/test_not_configured_default.rb +6 -0
  46. data/test/configurations/strict_with_blocks/test.rb +16 -0
  47. data/test/configurations/strict_with_blocks/test_defaults.rb +6 -0
  48. data/test/configurations/strict_with_blocks/test_hash_methods.rb +14 -0
  49. data/test/configurations/strict_with_blocks/test_methods.rb +6 -0
  50. data/test/configurations/strict_with_blocks/test_not_configured.rb +6 -0
  51. data/test/configurations/strict_with_blocks/test_not_configured_default.rb +6 -0
  52. data/test/support/setup.rb +173 -0
  53. data/test/support/shared.rb +11 -0
  54. data/test/test_helper.rb +6 -5
  55. metadata +148 -65
  56. data/test/configurations/test_configurable_with_blocks_configuration.rb +0 -54
  57. data/test/configurations/test_configuration.rb +0 -182
  58. data/test/configurations/test_configuration_methods.rb +0 -85
  59. data/test/configurations/test_stricter_configuration.rb +0 -173
  60. data/test/support/testmodules.rb +0 -10
@@ -1,54 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestStricterConfigurationWithBlock < Minitest::Test
4
-
5
- module BlocksConfigurationTestModule
6
- include Configurations
7
- configurable :property1, :property2 do |value|
8
- value.to_s + 'oooh'
9
- end
10
- configurable String, :property3, property4: [:property5, :property6] do |value|
11
- raise ArgumentError, 'TEST2' unless %w(hello bye).include?(value)
12
- value
13
- end
14
- end
15
-
16
- def setup
17
- BlocksConfigurationTestModule.configure do |c|
18
- c.property1 = :one
19
- c.property2 = :two
20
- c.property3 = 'hello'
21
- c.property4.property5 = 'hello'
22
- c.property4.property6 = 'bye'
23
- end
24
-
25
- @configuration = BlocksConfigurationTestModule.configuration
26
- end
27
-
28
- def test_configurable_when_set_configurable_with_block
29
- assert_equal 'oneoooh', @configuration.property1
30
- assert_equal 'twooooh', @configuration.property2
31
- end
32
-
33
- def test_nested_configurable_when_set_configurable_with_block
34
- assert_equal 'hello', @configuration.property4.property5
35
- assert_equal 'bye', @configuration.property4.property6
36
- end
37
-
38
- def test_evaluates_block_after_type_assertion
39
- assert_raises Configurations::ConfigurationError, 'TEST2' do
40
- BlocksConfigurationTestModule.configure do |c|
41
- c.property4.property5 = :bla
42
- end
43
- end
44
- end
45
-
46
- def test_evaluates_block_for_nested_properties_when_set_configurable_with_block
47
- assert_raises ArgumentError, 'TEST2' do
48
- BlocksConfigurationTestModule.configure do |c|
49
- c.property4.property5 = 'oh'
50
- end
51
- end
52
- end
53
-
54
- end
@@ -1,182 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestConfiguration < Minitest::Test
4
-
5
- module ConfigurationTestModule
6
- include Configurations
7
- configuration_defaults do |c|
8
- c.uh.this.is.neat = 'NEAT'
9
- c.pah = 'PUH'
10
- c.overwrite.this = ''
11
- c.overwriteee = 'BLA'
12
- end
13
- end
14
-
15
- module ConfigurationDefaultTestModule
16
- include Configurations
17
- configuration_defaults do |c|
18
- c.set = 'SET'
19
- end
20
- end
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
-
37
- def setup
38
- ConfigurationTestModule.configure do |c|
39
- c.basic = 'BASIC'
40
- c.class = 'KEY'
41
- c.puts = 'OH'
42
- c.overwriteee = 'YEAH'
43
- c.overwrite.this = 'OVERWRITE'
44
- c.github.repo = 'github.com/beatrichartz/configurations'
45
- c.github.access_key = 'ABCDEF'
46
- c.something.else.entirely.nested.deep.below = 'something'
47
- end
48
-
49
- @configuration = ConfigurationTestModule.configuration
50
- @not_configured_configuration = ConfigurationNotConfiguredTestModule.configuration
51
- @defaults_configuration = ConfigurationDefaultTestModule.configuration
52
- end
53
-
54
- def test_configuration_is_subclass_of_host_module
55
- assert_equal true, ConfigurationTestModule.const_defined?(:Configuration)
56
- end
57
-
58
- def test_configuration_to_h
59
- assert_equal({
60
- uh:
61
- {
62
- this: { is: { neat: 'NEAT' } }
63
- },
64
- pah: 'PUH',
65
- puts: 'OH',
66
- overwrite: {
67
- this: 'OVERWRITE'
68
- },
69
- overwriteee: 'YEAH',
70
- basic: 'BASIC',
71
- class: 'KEY',
72
- github: {
73
- repo: 'github.com/beatrichartz/configurations',
74
- access_key: 'ABCDEF'
75
- },
76
- something: { else: { entirely: { nested: { deep: { below: 'something' } } } } }
77
- }, @configuration.to_h)
78
- end
79
-
80
- def test_configuration_from_h
81
- old_to_h = @configuration.to_h.dup
82
- assert_equal(old_to_h, ConfigurationTestModule.configure{ |c| c.from_h(old_to_h) }.to_h)
83
- end
84
-
85
- def test_not_configurable_unless_block_given
86
- assert_raises ArgumentError do
87
- ConfigurationTestModule.configure
88
- end
89
- end
90
-
91
- def test_defaults
92
- assert_equal 'PUH', @configuration.pah
93
- end
94
-
95
- def test_defaults_without_configure
96
- assert_equal 'SET', @defaults_configuration.set
97
- end
98
-
99
- def test_no_defaults_without_configure
100
- assert_nil ConfigurationNoDefaultTestModule.configuration
101
- end
102
-
103
- def test_defaults_overwrite
104
- assert_equal 'YEAH', @configuration.overwriteee
105
- end
106
-
107
- def test_nested_defaults
108
- assert_equal 'NEAT', @configuration.uh.this.is.neat
109
- end
110
-
111
- def test_nested_defaults_overwrite
112
- assert_equal 'OVERWRITE', @configuration.overwrite.this
113
- end
114
-
115
- def test_configurable
116
- assert_equal 'BASIC', @configuration.basic
117
- end
118
-
119
- def test_keywords_configurable
120
- assert_equal 'KEY', @configuration.class
121
- end
122
-
123
- def test_nested_properties_with_same_key_configurable
124
- assert_equal 'github.com/beatrichartz/configurations', @configuration.github.repo
125
- assert_equal 'ABCDEF', @configuration.github.access_key
126
- end
127
-
128
- def test_deeply_nested_properties_configurable
129
- assert_equal 'something', @configuration.something.else.entirely.nested.deep.below
130
- end
131
-
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
147
- end
148
- end
149
-
150
- def test_nested_not_configured_callback
151
- assert_raises ArgumentError do
152
- @not_configured_configuration.set.something
153
- end
154
- end
155
-
156
- def test_nested_configured_property_with_not_configured
157
- assert_equal 'SET', @not_configured_configuration.set.set
158
- end
159
-
160
- def test_respond_to_on_writer_while_writeable
161
- ConfigurationTestModule.configure do |c|
162
- assert_equal true, c.respond_to?(:pah=)
163
- end
164
- end
165
-
166
- def test_respond_to_on_writer_when_not_writeable
167
- assert_equal false, @configuration.respond_to?(:pah=)
168
- end
169
-
170
- def test_respond_to_on_kernel_method
171
- assert_equal true, @configuration.respond_to?(:raise)
172
- end
173
-
174
- def test_method_missing_on_non_kernel_method
175
- assert_nil @configuration.blabla
176
- end
177
-
178
- def test_respond_to_missing_on_non_kernel_method
179
- assert_equal true, @configuration.respond_to?(:bbaaaaa)
180
- end
181
-
182
- end
@@ -1,85 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestConfigurationMethods < Minitest::Test
4
-
5
- module ConfigurationMethodsClassModule
6
- include Configurations
7
-
8
- class MyClass
9
- attr_reader :props
10
- def initialize(*props)
11
- @props = props
12
- end
13
- end
14
-
15
- context = 'CONTEXT'
16
- configurable :property1, :property2
17
- configuration_method :method1 do
18
- MyClass.new(property1, property2)
19
- end
20
- configuration_method :method2 do
21
- context + property1.to_s
22
- end
23
- configuration_method :method3 do |arg|
24
- arg + property1.to_s
25
- end
26
- configuration_method :kernel_raise do
27
- raise StandardError, 'hell'
28
- end
29
- end
30
-
31
- module ConfigurationNoMethodsClassModule
32
- include Configurations
33
-
34
- configurable :property3
35
- end
36
-
37
- def setup
38
- ConfigurationMethodsClassModule.configure do |c|
39
- c.property1 = :one
40
- c.property2 = :two
41
- end
42
-
43
- ConfigurationNoMethodsClassModule.configure do |c|
44
- c.property3 = :three
45
- end
46
-
47
- @configuration = ConfigurationMethodsClassModule.configuration
48
- @no_method_configuration = ConfigurationNoMethodsClassModule.configuration
49
- end
50
-
51
- def test_configuration_method
52
- assert_equal [:one, :two], @configuration.method1.props
53
- end
54
-
55
- def test_configuration_method_with_context
56
- assert_equal 'CONTEXTone', @configuration.method2
57
- end
58
-
59
- def test_configuration_method_with_arguments
60
- assert_equal 'ARGone', @configuration.method3('ARG')
61
- end
62
-
63
- def test_kernel_methods_in_configuration_method
64
- assert_raises StandardError, 'hell' do
65
- @configuration.kernel_raise
66
- end
67
- end
68
-
69
- def test_configuration_method_overwrite
70
- assert_raises ArgumentError do
71
- ConfigurationMethodsClassModule.module_eval do
72
- configuration_method :property2 do |c|
73
- MyClass.new(c.property2)
74
- end
75
- end
76
- end
77
- end
78
-
79
- def test_configuration_methods_unaffected
80
- assert_raises NoMethodError do
81
- @no_method_configuration.method3('ARG')
82
- end
83
- end
84
-
85
- end
@@ -1,173 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestStricterConfiguration < Minitest::Test
4
- module StrictConfigurationTestModule
5
- include Configurations
6
-
7
- configurable :property1, :property2
8
- configurable String, :property3
9
- configurable Symbol, property4: :property5, property6: [:property7, :property8]
10
- configurable Fixnum, property6: :property14
11
- configurable Fixnum, property4: :property12
12
- configurable Array, property9: { property10: { property11: :property12 } }
13
- configurable Hash, property9: { property10: { property11: :property13 } }
14
- end
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
-
26
- def setup
27
- StrictConfigurationTestModule.configure do |c|
28
- c.property1 = 'BASIC1'
29
- c.property2 = 'BASIC2'
30
- c.property3 = 'STRING'
31
- c.property4.property5 = :something
32
- c.property4.property12 = 12
33
- c.property6.property7 = :anything
34
- c.property6.property8 = :everything
35
- c.property6.property14 = 555
36
- c.property9.property10.property11.property12 = %w(here I am)
37
- c.property9.property10.property11.property13 = { hi: :bye }
38
- end
39
- StrictConfigurationTestModuleDefaultsError.configure do |c|
40
- c.property1 = 'BASIC3'
41
- end
42
-
43
- @configuration = StrictConfigurationTestModule.configuration
44
- @configuration_defaults_error = StrictConfigurationTestModuleDefaultsError.configuration
45
- end
46
-
47
- def test_configurable_when_set_configurable
48
- assert_equal 'BASIC1', @configuration.property1
49
- assert_equal 'BASIC2', @configuration.property2
50
- end
51
-
52
- def test_configurable_when_set_nested_configurable
53
- assert_equal :something, @configuration.property4.property5
54
- end
55
-
56
- def test_configurable_with_nested_calls_and_deeply_nested_property
57
- assert_equal 12, @configuration.property4.property12
58
- end
59
-
60
- def test_configurable_with_nested_calls_and_added_property
61
- assert_equal 555, @configuration.property6.property14
62
- end
63
-
64
- def test_configurable_type_assertion_with_nested_calls_and_added_property
65
- assert_raises Configurations::ConfigurationError do
66
- StrictConfigurationTestModule.configure do |c|
67
- c.property6.property14 = ''
68
- end
69
- end
70
- end
71
-
72
- def test_strict_configuration_to_h
73
- assert_equal({
74
- property4: {
75
- property5: :something,
76
- property12: 12
77
- },
78
- property6: {
79
- property7: :anything,
80
- property8: :everything,
81
- property14: 555
82
- },
83
- property9: {
84
- property10: {
85
- property11: {
86
- property12: %w(here I am),
87
- property13: {
88
- hi: :bye
89
- }
90
- }
91
- }
92
- },
93
- property1: 'BASIC1',
94
- property2: 'BASIC2',
95
- property3: 'STRING'
96
- }, @configuration.to_h)
97
- end
98
-
99
- def test_strict_configuration_from_h
100
- old_to_h = @configuration.to_h.dup
101
- assert_equal(old_to_h, StrictConfigurationTestModule.configure{ |c| c.from_h(old_to_h) }.to_h)
102
- end
103
-
104
- def test_configurable_with_same_key_when_set_nested_configurable
105
- assert_equal :anything, @configuration.property6.property7
106
- assert_equal :everything, @configuration.property6.property8
107
- end
108
-
109
- def test_configurable_with_deeply_nested_property
110
- assert_equal %w(here I am), @configuration.property9.property10.property11.property12
111
- end
112
-
113
- def test_configurable_with_nested_calls_and_deeply_nested_property
114
- assert_equal({ hi: :bye }, @configuration.property9.property10.property11.property13)
115
- end
116
-
117
- def test_configurable_type_restricted_with_nested_calls_and_deeply_nested_property
118
- assert_raises Configurations::ConfigurationError do
119
- StrictConfigurationTestModule.configure do |c|
120
- c.property9.property10.property11.property13 = ''
121
- end
122
- end
123
- end
124
-
125
- def test_not_configurable_with_wrong_type
126
- assert_raises Configurations::ConfigurationError do
127
- StrictConfigurationTestModule.configure do |c|
128
- c.property3 = {}
129
- end
130
- end
131
- end
132
-
133
- def test_not_configurable_with_undefined_property
134
- assert_raises NoMethodError do
135
- StrictConfigurationTestModule.configure do |c|
136
- c.property4 = {}
137
- end
138
- end
139
- end
140
-
141
- def test_respond_to_with_undefined_property
142
- assert_equal false, @configuration.respond_to?(:property12)
143
- end
144
-
145
- def test_not_callable_with_undefined_property
146
- assert_raises NoMethodError do
147
- @configuration.property12
148
- end
149
- end
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
-
161
- def test_not_configurable_with_undefined_nested_property
162
- assert_raises NoMethodError do
163
- StrictConfigurationTestModule.configure do |c|
164
- c.property6.property9 = {}
165
- end
166
- end
167
- end
168
-
169
- def test_callable_with_undefined_nested_property
170
- assert_nil @configuration.property6.property9
171
- end
172
-
173
- end