attribute_struct 0.2.8 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/attribute_struct.gemspec +1 -1
- data/lib/attribute_struct/attribute_struct.rb +6 -4
- data/lib/attribute_struct/version.rb +1 -1
- metadata +2 -11
- data/Gemfile +0 -5
- data/Gemfile.lock +0 -16
- data/attribute_struct-0.2.6.gem +0 -0
- data/attribute_struct-0.2.7.gem +0 -0
- data/test/spec.rb +0 -3
- data/test/specs/basic.rb +0 -169
- data/test/specs/camel.rb +0 -80
- data/test/specs/collapse.rb +0 -77
- data/test/specs/merging.rb +0 -55
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9b868b2158e6d4180a0284e6570aae190f912dd
|
4
|
+
data.tar.gz: fea21780da1c0b5aec42317079e94201089ce9a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d808083f54a73f7d445fe5c2e87433930b18907267ed3bd917679783a1afc82746622b7dc123a21cd9db4b158920a4b88ebf0fd4ea5b53162c327a3752e39c25
|
7
|
+
data.tar.gz: c0e1f1ef8ffdd5bf32de73ab95d13680829b751470d1c6d1f2d4d7069a2d1eb48753942435e57afd2159533fe972cab0f6e0c1193e0650023238bc0f86092f2a
|
data/CHANGELOG.md
CHANGED
data/attribute_struct.gemspec
CHANGED
@@ -10,5 +10,5 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = 'http://github.com/chrisroberts/attribute_struct'
|
11
11
|
s.description = 'Attribute structures'
|
12
12
|
s.require_path = 'lib'
|
13
|
-
s.files = Dir['
|
13
|
+
s.files = Dir['lib/**/*'] + %w(attribute_struct.gemspec README.md CHANGELOG.md CONTRIBUTING.md LICENSE)
|
14
14
|
end
|
@@ -46,6 +46,8 @@ class AttributeStruct < BasicObject
|
|
46
46
|
|
47
47
|
end
|
48
48
|
|
49
|
+
class CollapseArray < ::Array; end
|
50
|
+
|
49
51
|
# @return [Truthy, Falsey] current camelizing setting
|
50
52
|
attr_reader :_camel_keys
|
51
53
|
# @return [AtributeStruct::AttributeHash, Mash] holding space for state
|
@@ -194,7 +196,7 @@ class AttributeStruct < BasicObject
|
|
194
196
|
end
|
195
197
|
@table[sym] = result
|
196
198
|
else
|
197
|
-
if(args.size > 1)
|
199
|
+
if(args.size > 1 && args.all?{|i| i.is_a?(::String) || i.is_a?(::Symbol)})
|
198
200
|
@table[sym] = _klass_new unless @table[sym].is_a?(_klass)
|
199
201
|
endpoint = args.inject(@table[sym]) do |memo, k|
|
200
202
|
unless(memo[k].is_a?(_klass))
|
@@ -205,11 +207,11 @@ class AttributeStruct < BasicObject
|
|
205
207
|
return endpoint # custom break out
|
206
208
|
else
|
207
209
|
if(_state(:value_collapse) && !(leaf = @table[sym]).nil?)
|
208
|
-
leaf =
|
209
|
-
leaf << args.first
|
210
|
+
leaf = CollapseArray.new.push(leaf) unless leaf.is_a?(CollapseArray)
|
211
|
+
leaf << (args.size > 1 ? args : args.first)
|
210
212
|
@table[sym] = leaf
|
211
213
|
else
|
212
|
-
@table[sym] = args.first
|
214
|
+
@table[sym] = (args.size > 1 ? args : args.first)
|
213
215
|
end
|
214
216
|
end
|
215
217
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attribute_struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Roberts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Attribute structures
|
14
14
|
email: chrisroberts.code@gmail.com
|
@@ -18,12 +18,8 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- CHANGELOG.md
|
20
20
|
- CONTRIBUTING.md
|
21
|
-
- Gemfile
|
22
|
-
- Gemfile.lock
|
23
21
|
- LICENSE
|
24
22
|
- README.md
|
25
|
-
- attribute_struct-0.2.6.gem
|
26
|
-
- attribute_struct-0.2.7.gem
|
27
23
|
- attribute_struct.gemspec
|
28
24
|
- lib/attribute_struct.rb
|
29
25
|
- lib/attribute_struct/attribute_hash.rb
|
@@ -31,11 +27,6 @@ files:
|
|
31
27
|
- lib/attribute_struct/irb_compat.rb
|
32
28
|
- lib/attribute_struct/monkey_camels.rb
|
33
29
|
- lib/attribute_struct/version.rb
|
34
|
-
- test/spec.rb
|
35
|
-
- test/specs/basic.rb
|
36
|
-
- test/specs/camel.rb
|
37
|
-
- test/specs/collapse.rb
|
38
|
-
- test/specs/merging.rb
|
39
30
|
homepage: http://github.com/chrisroberts/attribute_struct
|
40
31
|
licenses:
|
41
32
|
- Apache 2.0
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
data/attribute_struct-0.2.6.gem
DELETED
Binary file
|
data/attribute_struct-0.2.7.gem
DELETED
Binary file
|
data/test/spec.rb
DELETED
data/test/specs/basic.rb
DELETED
@@ -1,169 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
|
3
|
-
describe AttributeStruct do
|
4
|
-
describe 'Basic usage' do
|
5
|
-
describe 'instance based population' do
|
6
|
-
before do
|
7
|
-
@struct = AttributeStruct.new
|
8
|
-
@struct.method.based.access true
|
9
|
-
@struct.method('and', 'parameter', 'based').access true
|
10
|
-
@struct.block do
|
11
|
-
based.access true
|
12
|
-
end
|
13
|
-
@struct.block('and', 'parameter', 'based') do
|
14
|
-
access true
|
15
|
-
end
|
16
|
-
@struct.block_only do
|
17
|
-
access true
|
18
|
-
end
|
19
|
-
@struct._set('1') do
|
20
|
-
value true
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'allows method based access' do
|
25
|
-
@struct.method.based.access.must_equal true
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'allows method and parameter based access' do
|
29
|
-
@struct.method.and.parameter.based.access.must_equal true
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'allows block based access' do
|
33
|
-
@struct.block.based.access.must_equal true
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'allows block and parameter based access' do
|
37
|
-
@struct.block.and.parameters.based.access.must_equal true
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'allows block only access' do
|
41
|
-
@struct.block_only.access.must_equal true
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'allows hash style access' do
|
45
|
-
@struct['method'][:based].access.must_equal true
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'allows _set for invalid method names' do
|
49
|
-
@struct['1'].value.must_equal true
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe 'block based creation' do
|
54
|
-
before do
|
55
|
-
@struct = AttributeStruct.new do
|
56
|
-
enable true
|
57
|
-
access.user true
|
58
|
-
access do
|
59
|
-
port 80
|
60
|
-
transport :udp
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'creates struct with block content' do
|
66
|
-
@struct.enable.must_equal true
|
67
|
-
@struct.access.user.must_equal true
|
68
|
-
@struct.access.port.must_equal 80
|
69
|
-
@struct.access.transport.must_equal :udp
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
describe 'nil behavior' do
|
75
|
-
before do
|
76
|
-
@struct = AttributeStruct.new
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'should return as nil' do
|
80
|
-
@struct.must_be_nil
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe 'array helper' do
|
85
|
-
before do
|
86
|
-
@struct = AttributeStruct.new do
|
87
|
-
my_array _array(
|
88
|
-
-> {
|
89
|
-
working true
|
90
|
-
},
|
91
|
-
:item
|
92
|
-
)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'should contain an array at my_array' do
|
97
|
-
@struct.my_array.must_be_kind_of Array
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'should contain symbol in array' do
|
101
|
-
@struct.my_array.must_include :item
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'should contain an AttrubuteStruct instance in array' do
|
105
|
-
assert @struct.my_array.detect{|i| i.is_a?(AttributeStruct)}
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'should contain working attribute in array struct' do
|
109
|
-
@struct.my_array.detect{|i| i.is_a?(AttributeStruct)}.working.must_equal true
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
describe 'entry deletion' do
|
114
|
-
before do
|
115
|
-
@struct = AttributeStruct.new do
|
116
|
-
value1 true
|
117
|
-
value2 true
|
118
|
-
end
|
119
|
-
@struct._delete(:value2)
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'should contain value1' do
|
123
|
-
@struct.value1.must_equal true
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'should not contain value2 in keys' do
|
127
|
-
@struct._keys.wont_include 'value2'
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'should report nil for value2' do
|
131
|
-
@struct.value2.must_be_nil
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
describe 'dumps' do
|
136
|
-
before do
|
137
|
-
@struct = AttributeStruct.new do
|
138
|
-
value1 true
|
139
|
-
value2 do
|
140
|
-
nested true
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'should dump to a hash type value' do
|
146
|
-
@struct._dump.must_be_kind_of Hash
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'should include all defined values' do
|
150
|
-
dump = @struct._dump
|
151
|
-
dump['value1'].must_equal true
|
152
|
-
dump['value2'].must_be_kind_of Hash
|
153
|
-
dump['value2']['nested'].must_equal true
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
describe 'loads' do
|
158
|
-
before do
|
159
|
-
@hash = {'value1' => true, 'value2' => {'nested' => true}}
|
160
|
-
@struct = AttributeStruct.new(@hash)
|
161
|
-
end
|
162
|
-
|
163
|
-
it 'should include all values defined in hash' do
|
164
|
-
@struct.value1.must_equal true
|
165
|
-
@struct.value2.nested.must_equal true
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
data/test/specs/camel.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
|
3
|
-
describe AttributeStruct do
|
4
|
-
describe 'Camel usage' do
|
5
|
-
before do
|
6
|
-
AttributeStruct.camel_keys = true
|
7
|
-
@struct = AttributeStruct.new do
|
8
|
-
value_one true
|
9
|
-
value_two do
|
10
|
-
nesting true
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
after do
|
15
|
-
AttributeStruct.camel_keys = false
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should camel case keys when dumped' do
|
19
|
-
@struct._dump.keys.must_include 'ValueOne'
|
20
|
-
@struct._dump.keys.must_include 'ValueTwo'
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should allow explicit disable on keys' do
|
24
|
-
@struct._set('not_camel'._no_hump, true)
|
25
|
-
@struct._dump.keys.must_include 'not_camel'
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should allow implicit disable on nested structs' do
|
29
|
-
@struct.disable_camel do |struct|
|
30
|
-
struct._camel_keys_set(:auto_disable)
|
31
|
-
not_camel true
|
32
|
-
not_camel_nest do
|
33
|
-
no_camel_here true
|
34
|
-
end
|
35
|
-
end
|
36
|
-
dump = @struct._dump
|
37
|
-
dump['DisableCamel'][:not_camel].must_equal true
|
38
|
-
dump['DisableCamel'][:not_camel_nest][:no_camel_here].must_equal true
|
39
|
-
dump['ValueOne'].must_equal true
|
40
|
-
dump['ValueTwo']['Nesting'].must_equal true
|
41
|
-
end
|
42
|
-
end
|
43
|
-
describe 'Camel enabled imports' do
|
44
|
-
before do
|
45
|
-
@struct = AttributeStruct.new
|
46
|
-
@struct._camel_keys = true
|
47
|
-
@struct._camel_keys_set(:auto_discovery)
|
48
|
-
@struct._load(
|
49
|
-
{
|
50
|
-
'Fubar' => {
|
51
|
-
'FooBar' => true,
|
52
|
-
'FeeBar' => {
|
53
|
-
'FauxBar' => 'done'
|
54
|
-
},
|
55
|
-
'FooDar' => {
|
56
|
-
'snake_case' => {
|
57
|
-
'still_snake' => {
|
58
|
-
'NowCamel' => {
|
59
|
-
'CamelCamel' => 'yep, a camel'
|
60
|
-
}
|
61
|
-
}
|
62
|
-
}
|
63
|
-
}
|
64
|
-
}
|
65
|
-
}
|
66
|
-
)
|
67
|
-
@struct._camel_keys_set(nil)
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'should properly export keys after discovery' do
|
71
|
-
@struct.fubar.new_bar.halt 'new_value'
|
72
|
-
@struct.fubar.foo_dar.snake_case.new_snake 'snake!'
|
73
|
-
@struct.fubar.foo_dar.snake_case.still_snake.now_camel.new_camel 'a camel!'
|
74
|
-
hash = @struct._dump
|
75
|
-
hash['Fubar']['NewBar']['Halt'].must_equal 'new_value'
|
76
|
-
hash['Fubar']['FooDar']['snake_case']['new_snake'].must_equal 'snake!'
|
77
|
-
hash['Fubar']['FooDar']['snake_case']['still_snake']['NowCamel']['NewCamel'].must_equal 'a camel!'
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
data/test/specs/collapse.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
|
3
|
-
describe AttributeStruct do
|
4
|
-
describe 'Collapse' do
|
5
|
-
describe 'direct value set' do
|
6
|
-
|
7
|
-
describe 'When values are not collapsed' do
|
8
|
-
before do
|
9
|
-
@struct = AttributeStruct.new
|
10
|
-
@struct.direct.assignment 1
|
11
|
-
@struct.direct.assignment 2
|
12
|
-
@dump = @struct._dump
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should return last set value' do
|
16
|
-
@dump['direct']['assignment'].must_equal 2
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'When values are collapsed' do
|
21
|
-
before do
|
22
|
-
@struct = AttributeStruct.new
|
23
|
-
@struct._set_state(:value_collapse => true)
|
24
|
-
@struct.direct.assignment 1
|
25
|
-
@struct.direct.assignment 2
|
26
|
-
@dump = @struct._dump
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should return both assigned values as an array' do
|
30
|
-
@dump['direct']['assignment'].must_equal [1,2]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
describe 'block value set' do
|
37
|
-
|
38
|
-
describe 'When values are not collapsed' do
|
39
|
-
before do
|
40
|
-
@struct = AttributeStruct.new
|
41
|
-
@struct.direct do
|
42
|
-
assignment true
|
43
|
-
end
|
44
|
-
@struct.direct do
|
45
|
-
assignment false
|
46
|
-
end
|
47
|
-
@dump = @struct._dump
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should return last set value' do
|
51
|
-
@dump['direct']['assignment'].must_equal false
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
describe 'When values are collapsed' do
|
57
|
-
before do
|
58
|
-
@struct = AttributeStruct.new
|
59
|
-
@struct._set_state(:value_collapse => true)
|
60
|
-
@struct.direct do
|
61
|
-
assignment true
|
62
|
-
end
|
63
|
-
@struct.direct do
|
64
|
-
assignment false
|
65
|
-
end
|
66
|
-
@dump = @struct._dump
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'should return both assigned values as an array' do
|
70
|
-
@dump['direct']['assignment'].must_equal [true, false]
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
data/test/specs/merging.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
|
3
|
-
describe AttributeStruct do
|
4
|
-
describe 'Merging usage' do
|
5
|
-
before do
|
6
|
-
@struct1 = AttributeStruct.new do
|
7
|
-
value1 true
|
8
|
-
value2 do
|
9
|
-
nesting true
|
10
|
-
end
|
11
|
-
end
|
12
|
-
@struct2 = AttributeStruct.new do
|
13
|
-
value2 do
|
14
|
-
nesting false
|
15
|
-
squashing true
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'new struct from merge' do
|
21
|
-
before do
|
22
|
-
@struct = @struct1._merge(@struct2)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should have correct value for value1' do
|
26
|
-
@struct.value1.must_equal true
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should have correct value for squashing' do
|
30
|
-
@struct.value2.squashing.must_equal true
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should have correct value for nesting' do
|
34
|
-
@struct.value2.nesting.must_equal false
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe 'update struct from merge' do
|
39
|
-
before do
|
40
|
-
@struct = AttributeStruct.new do
|
41
|
-
test_value true
|
42
|
-
end
|
43
|
-
@struct._merge!(@struct1)
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should contain test_value' do
|
47
|
-
@struct.test_value.must_equal true
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should contain value1' do
|
51
|
-
@struct.value1.must_equal true
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|