adaptiveconfiguration 1.0.0.beta04 → 1.0.0.beta06
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.
- checksums.yaml +4 -4
- data/adaptiveconfiguration.gemspec +1 -1
- data/lib/adaptive_configuration/builder.rb +1 -0
- data/lib/adaptive_configuration/context.rb +42 -30
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e6d7ffc7756d8ea2cb2d685ef00ca01561d232c99852516b38b7bf1ce72cb66
|
4
|
+
data.tar.gz: bb716f63caf1e4fec6a90da636a30a4bcfc7b546f610d548f275bb630780f2bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbb8df8e89fab329b3ca8464a8088c0617b800ab981be36cae596debb7f29a26b2768520665926d2a30148074f981d59dbbade409932b5c02407efdcb600b5cc
|
7
|
+
data.tar.gz: ae9e3c1d6fde00f4136edf6e4cc9cb85e621170f78ba52c86211bb1121e3bfe20e9e76fb606bd009e218957c0a6260a127e03342c494cb733d4803d2ad8973ec
|
@@ -16,6 +16,7 @@ module AdaptiveConfiguration
|
|
16
16
|
Time => ->( v ) { v.respond_to?( :to_time ) ? v.to_time : Time.parse( v.to_s ) },
|
17
17
|
URI => ->( v ) { URI.parse( v.to_s ) },
|
18
18
|
String => ->( v ) { String( v ) },
|
19
|
+
Symbol => ->( v ) { v.respond_to?( :to_sym ) ? v.to_sym : nil },
|
19
20
|
Rational => ->( v ) { Rational( v ) },
|
20
21
|
Float => ->( v ) { Float( v ) },
|
21
22
|
Integer => ->( v ) { Integer( v ) },
|
@@ -1,12 +1,14 @@
|
|
1
1
|
module AdaptiveConfiguration
|
2
2
|
class Context < BasicObject
|
3
3
|
|
4
|
+
include ::PP::ObjectMixin if defined?( ::PP )
|
5
|
+
|
4
6
|
attr_reader :errors
|
5
7
|
|
6
8
|
def initialize( values = nil, definitions:, converters: )
|
9
|
+
raise ArgumentError, 'The Scaffold initialitization attributes must be a Hash pr Hash-like.'\
|
10
|
+
unless values.nil? || ( values.respond_to?( :[] ) && values.respond_to?( :key? ) )
|
7
11
|
|
8
|
-
values = values ? values.transform_keys( &:to_sym ) : {}
|
9
|
-
|
10
12
|
@converters = converters&.dup
|
11
13
|
@definitions = definitions&.dup
|
12
14
|
@values = {}
|
@@ -14,21 +16,13 @@ module AdaptiveConfiguration
|
|
14
16
|
|
15
17
|
@definitions.each do | key, definition |
|
16
18
|
name = definition[ :as ] || key
|
17
|
-
if definition
|
18
|
-
|
19
|
-
|
20
|
-
converters: @converters, definitions: definition[ :definitions ],
|
21
|
-
)
|
22
|
-
@values[ name ] = context unless context.empty?
|
23
|
-
elsif definition.key?( :default )
|
24
|
-
@values[ name ] = definition[ :array ] ?
|
25
|
-
::Kernel.method( :Array ).call( definition[ :default ] ) :
|
26
|
-
definition[ :default ]
|
27
|
-
# note: this is needed to know when an array paramter which was initially assigned
|
19
|
+
if definition.key?( :default )
|
20
|
+
self.__send__( key, definition[ :default ] )
|
21
|
+
# note: this is needed to know when an array parameter which was initially assigned
|
28
22
|
# to a default should be replaced rather than appended
|
29
23
|
definition[ :default_assigned ] = true
|
30
24
|
end
|
31
|
-
self.__send__( key, values[ key ] ) if values
|
25
|
+
self.__send__( key, values[ key ] ) if values && values.key?( key )
|
32
26
|
end
|
33
27
|
|
34
28
|
end
|
@@ -41,6 +35,10 @@ module AdaptiveConfiguration
|
|
41
35
|
@values.empty?
|
42
36
|
end
|
43
37
|
|
38
|
+
def key?( key )
|
39
|
+
@values.key?( key )
|
40
|
+
end
|
41
|
+
|
44
42
|
def []( key )
|
45
43
|
@values[ key ]
|
46
44
|
end
|
@@ -93,7 +91,13 @@ module AdaptiveConfiguration
|
|
93
91
|
end
|
94
92
|
|
95
93
|
def inspect
|
96
|
-
@values.inspect
|
94
|
+
{ values: @values, definitions: @definitions }.inspect
|
95
|
+
end
|
96
|
+
|
97
|
+
if defined?( ::PP )
|
98
|
+
def pretty_print( pp )
|
99
|
+
pp.pp( { values: @values, definitions: @definitions } )
|
100
|
+
end
|
97
101
|
end
|
98
102
|
|
99
103
|
def class
|
@@ -107,20 +111,23 @@ module AdaptiveConfiguration
|
|
107
111
|
alias :kind_of? :is_a?
|
108
112
|
|
109
113
|
def method_missing( method, *args, &block )
|
110
|
-
|
114
|
+
|
111
115
|
if @definitions.key?( method )
|
112
|
-
|
113
116
|
definition = @definitions[ method ]
|
114
117
|
name = definition[ :as ] || method
|
115
118
|
|
116
119
|
unless definition[ :array ]
|
117
120
|
if definition[ :type ] == :group
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
121
|
+
argument = args.first
|
122
|
+
context = @values[ name ]
|
123
|
+
if context.nil? || argument
|
124
|
+
context =
|
125
|
+
Context.new(
|
126
|
+
argument,
|
127
|
+
converters: @converters,
|
128
|
+
definitions: definition[ :definitions ]
|
129
|
+
)
|
130
|
+
end
|
124
131
|
context.instance_eval( &block ) if block
|
125
132
|
@values[ name ] = context
|
126
133
|
else
|
@@ -133,13 +140,17 @@ module AdaptiveConfiguration
|
|
133
140
|
::Array.new :
|
134
141
|
@values[ name ] || ::Array.new
|
135
142
|
if definition[ :type ] == :group
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
+
values = [ args.first ].flatten
|
144
|
+
values = values.map do | v |
|
145
|
+
context = Context.new(
|
146
|
+
v,
|
147
|
+
converters: @converters,
|
148
|
+
definitions: definition[ :definitions ]
|
149
|
+
)
|
150
|
+
context.instance_eval( &block ) if block
|
151
|
+
context
|
152
|
+
end
|
153
|
+
@values[ name ].concat( values )
|
143
154
|
else
|
144
155
|
values = ::Kernel.method( :Array ).call( args.first )
|
145
156
|
if type = definition[ :type ]
|
@@ -243,6 +254,7 @@ module AdaptiveConfiguration
|
|
243
254
|
else
|
244
255
|
|
245
256
|
if definition[ :type ] == :group
|
257
|
+
groups = ::Kernel.method( :Array ).call( value )
|
246
258
|
groups.each do | group |
|
247
259
|
group.__validate_values( "#{ ( path || '' ) + ( path ? '/' : '' ) + key.to_s }", &block )
|
248
260
|
@errors.concat( group.errors )
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adaptiveconfiguration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.beta06
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kristoph Cichocki-Romanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|