attribute_struct 0.2.10 → 0.2.12
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/CHANGELOG.md +4 -0
- data/README.md +3 -3
- data/lib/attribute_struct/attribute_struct.rb +9 -0
- data/lib/attribute_struct/monkey_camels.rb +53 -49
- data/lib/attribute_struct/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4678195877f88a043df9e50bb70bd2b15d6e0de6
|
4
|
+
data.tar.gz: 67a4f4870ed31aeabb2e43602c8d996bc2f550ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d0d0c9f6dd9fb55e757fb2a91988cf7d58ded85d393e75f03261d27f4df0fe9692b1d64385e6cc186079a8e3a7cbb4be494101bd4b6cbf03689d4be17aace36
|
7
|
+
data.tar.gz: 27a40c5108a547180fcbb91f2f78db07adf405e42b6ed9a3a3b12a3c533ff594ba52d92f10d84f6d1b689e05586b7cd4d4fe70a545864de136dbdae54125fb91
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# AttributeStruct
|
2
2
|
|
3
3
|
This is a helper library that essentially builds hashes. It
|
4
4
|
wraps hash building with a nice DSL to make it slightly cleaner,
|
@@ -8,7 +8,7 @@ more robust, and provide extra features.
|
|
8
8
|
|
9
9
|
* [](https://travis-ci.org/chrisroberts/attribute_struct)
|
10
10
|
|
11
|
-
|
11
|
+
## Usage
|
12
12
|
|
13
13
|
```ruby
|
14
14
|
require 'attribute_struct'
|
@@ -51,7 +51,7 @@ which gives:
|
|
51
51
|
"client"=>{"general"=>{"enabled"=>false}}}}
|
52
52
|
```
|
53
53
|
|
54
|
-
|
54
|
+
## IRB
|
55
55
|
|
56
56
|
IRB expects some things to be around like `#inspect` and `#to_s`. Before
|
57
57
|
using `AttributeStruct` in IRB, enable compat mode:
|
@@ -46,6 +46,7 @@ class AttributeStruct < BasicObject
|
|
46
46
|
|
47
47
|
end
|
48
48
|
|
49
|
+
# Specialized array for collapsing values
|
49
50
|
class CollapseArray < ::Array; end
|
50
51
|
|
51
52
|
# @return [Truthy, Falsey] current camelizing setting
|
@@ -76,6 +77,7 @@ class AttributeStruct < BasicObject
|
|
76
77
|
def _build(&block)
|
77
78
|
self.instance_exec(&block)
|
78
79
|
end
|
80
|
+
alias_method :build!, :_build
|
79
81
|
|
80
82
|
# Set state into current context
|
81
83
|
#
|
@@ -84,6 +86,7 @@ class AttributeStruct < BasicObject
|
|
84
86
|
def _set_state(args={})
|
85
87
|
_arg_state.merge!(args)
|
86
88
|
end
|
89
|
+
alias_method :set_state!, :_set_state
|
87
90
|
|
88
91
|
# Value of requested state
|
89
92
|
#
|
@@ -99,6 +102,7 @@ class AttributeStruct < BasicObject
|
|
99
102
|
end
|
100
103
|
end
|
101
104
|
end
|
105
|
+
alias_method :state!, :_state
|
102
106
|
|
103
107
|
# Enable/disable camel keys
|
104
108
|
#
|
@@ -238,11 +242,13 @@ class AttributeStruct < BasicObject
|
|
238
242
|
def _keys
|
239
243
|
_data.keys
|
240
244
|
end
|
245
|
+
alias_method :keys!, :_keys
|
241
246
|
|
242
247
|
# @return [AttributeStruct::AttributeHash, Mash] underlying struct data
|
243
248
|
def _data
|
244
249
|
@table
|
245
250
|
end
|
251
|
+
alias_method :data!, :_data
|
246
252
|
|
247
253
|
# Delete entry from struct
|
248
254
|
#
|
@@ -302,6 +308,7 @@ class AttributeStruct < BasicObject
|
|
302
308
|
end
|
303
309
|
self
|
304
310
|
end
|
311
|
+
alias_method :load!, :_load
|
305
312
|
|
306
313
|
# Perform deep merge
|
307
314
|
#
|
@@ -426,6 +433,7 @@ class AttributeStruct < BasicObject
|
|
426
433
|
@_parent = obj if obj
|
427
434
|
@_parent
|
428
435
|
end
|
436
|
+
alias_method :parent!, :_parent
|
429
437
|
|
430
438
|
# @return [AttributeStruct, NilClass] root of the struct or nil if self is root
|
431
439
|
def _root
|
@@ -435,6 +443,7 @@ class AttributeStruct < BasicObject
|
|
435
443
|
end
|
436
444
|
r
|
437
445
|
end
|
446
|
+
alias_method :root!, :_root
|
438
447
|
|
439
448
|
# Create an Array and evaluate discovered AttributeStructs
|
440
449
|
#
|
@@ -1,70 +1,74 @@
|
|
1
1
|
require 'attribute_struct'
|
2
2
|
|
3
|
-
|
3
|
+
unless(defined?(MonkeyCamels))
|
4
4
|
|
5
|
-
|
6
|
-
def included(klass)
|
7
|
-
klass.class_eval do
|
5
|
+
module MonkeyCamels
|
8
6
|
|
9
|
-
|
7
|
+
class << self
|
8
|
+
def included(klass)
|
9
|
+
klass.class_eval do
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
include Humps
|
12
|
+
|
13
|
+
alias_method :un_camel_to_s, :to_s
|
14
|
+
alias_method :to_s, :camel_to_s
|
15
|
+
alias_method :un_camel_initialize_copy, :initialize_copy
|
16
|
+
alias_method :initialize_copy, :camel_initialize_copy
|
17
|
+
end
|
15
18
|
end
|
16
19
|
end
|
17
|
-
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
# Create a camel copy based on settings
|
22
|
+
#
|
23
|
+
# @return [String]
|
24
|
+
def camel_initialize_copy(orig)
|
25
|
+
new_val = un_camel_initialize_copy(orig)
|
26
|
+
orig._camel? ? new_val : new_val._no_hump
|
27
|
+
end
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
# Provide string formatted based on hump setting
|
30
|
+
#
|
31
|
+
# @return [String]
|
32
|
+
def camel_to_s
|
33
|
+
val = un_camel_to_s
|
34
|
+
_camel? ? val : val._no_hump
|
35
|
+
end
|
34
36
|
|
35
|
-
|
37
|
+
module Humps
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
# @return [TrueClass, FalseClass] camelized
|
40
|
+
def _camel?
|
41
|
+
!@__not_camel
|
42
|
+
end
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
# @return [self] disable camelizing
|
45
|
+
def _no_hump
|
46
|
+
@__not_camel = true
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [self] enable camelizing
|
51
|
+
def _hump
|
52
|
+
@__not_camel = false
|
53
|
+
self
|
54
|
+
end
|
47
55
|
|
48
|
-
# @return [self] enable camelizing
|
49
|
-
def _hump
|
50
|
-
@__not_camel = false
|
51
|
-
self
|
52
56
|
end
|
53
57
|
|
54
58
|
end
|
55
59
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
String.send(:include, MonkeyCamels)
|
60
|
-
Symbol.send(:include, MonkeyCamels)
|
60
|
+
# Force some monkeys around
|
61
|
+
String.send(:include, MonkeyCamels)
|
62
|
+
Symbol.send(:include, MonkeyCamels)
|
61
63
|
|
62
|
-
# Specialized String type
|
63
|
-
class CamelString < String
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
# Specialized String type
|
65
|
+
class CamelString < String
|
66
|
+
def initialize(val=nil)
|
67
|
+
super
|
68
|
+
if(val.respond_to?(:_camel?))
|
69
|
+
_no_hump unless val._camel?
|
70
|
+
end
|
68
71
|
end
|
69
72
|
end
|
73
|
+
|
70
74
|
end
|