attribute_struct 0.2.20 → 0.2.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d48c85e42d6879e924f24f40bada06f9f1b6c1b0
4
- data.tar.gz: 6f41e2b3229b0229f9edc53943e23c6e086453b2
3
+ metadata.gz: b824f9b0f1c12f9d33cf496af7d88899dc9634e7
4
+ data.tar.gz: 1a6e058a77f4ebc0189a8367b56797208519ed1c
5
5
  SHA512:
6
- metadata.gz: f84ee43890fd47d888a3df06d1f6009de2a5b684af3dc9743207534372c5c781c21d9037db87f52f1571130a24d08e950e4427e9d034510c26ec78d8d086329a
7
- data.tar.gz: 16e3b57dc6f98c57e4b73da3c0e94323a19c0cc1141d60bb79900b26ce7a1ab9beae5ef6019c3f47ad57590424e0a50599762ef85296a98d0e3f6d81c28c2f79
6
+ metadata.gz: 73056b0aaf9645e3a51db712dd5d4351483760135a26e395fa4170e507bb21c8488f3fdb1eb816a9e1e5a29a925c89a553fd596dacb339f5cef9ab2b7c8bb25d
7
+ data.tar.gz: 3350700bcd1745bf4ffa03d5f25b840ea7908dd554a50cb147ac2e9d2cf31a401e20e68780974d11ea21027359ac42ae5e2b1c208bc6a811609bc488aa2bd13f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v0.2.22
2
+ * Add more helper method bang aliases
3
+ * Properly persist camel data on Hash keys
4
+ * Support optional automatic AttributeStruct loading on Hash set
5
+
1
6
  ## v0.2.20
2
7
  * Fix: remove nil structs
3
8
 
@@ -1,4 +1,4 @@
1
- require 'attribute_struct/attribute_struct'
1
+ require 'attribute_struct'
2
2
 
3
3
  class AttributeStruct
4
4
 
@@ -211,7 +211,7 @@ class AttributeStruct
211
211
  #
212
212
  # @api private
213
213
  def convert_key(key)
214
- key.kind_of?(Symbol) ? key.to_s : key
214
+ key.kind_of?(Symbol) || key.kind_of?(String) ? CamelString.new(key.to_s) : key
215
215
  end
216
216
 
217
217
  # @param value<Object> The value to convert.
@@ -1,7 +1,9 @@
1
- require 'attribute_struct/irb_compat'
1
+ require 'attribute_struct'
2
2
 
3
3
  class AttributeStruct < BasicObject
4
4
 
5
+ autoload :Mash, 'attribute_struct/attribute_hash'
6
+
5
7
  class << self
6
8
 
7
9
  # @return [Truthy, Falsey] global flag for camel keys
@@ -214,14 +216,31 @@ class AttributeStruct < BasicObject
214
216
  end
215
217
  return endpoint # custom break out
216
218
  else
219
+ if(args.size > 1)
220
+ val = args.map do |v|
221
+ if(v.is_a?(::Hash) && _state(:hash_load_struct))
222
+ val = _klass_new
223
+ val._load(v)
224
+ else
225
+ v
226
+ end
227
+ end
228
+ else
229
+ if(args.first.is_a?(::Hash) && _state(:hash_load_struct))
230
+ val = _klass_new
231
+ val._load(args.first)
232
+ else
233
+ val = args.first
234
+ end
235
+ end
217
236
  if(_state(:value_collapse) && !(leaf = @table[sym]).nil?)
218
237
  unless(leaf.is_a?(CollapseArray))
219
238
  leaf = CollapseArray.new.push(leaf)
220
239
  end
221
- leaf << (args.size > 1 ? args : args.first)
240
+ leaf << val
222
241
  @table[sym] = leaf
223
242
  else
224
- @table[sym] = (args.size > 1 ? args : args.first)
243
+ @table[sym] = val
225
244
  end
226
245
  end
227
246
  end
@@ -301,7 +320,6 @@ class AttributeStruct < BasicObject
301
320
  end
302
321
  end
303
322
  hashish.each do |key, value|
304
- key = key.dup
305
323
  if(value.is_a?(::Enumerable))
306
324
  flat = value.map do |v|
307
325
  v.is_a?(::Hash) ? _klass.new(v) : v
@@ -380,8 +398,8 @@ class AttributeStruct < BasicObject
380
398
  # @param args [Object] argument list (:force will force processing)
381
399
  # @return [String, Symbol]
382
400
  def _process_key(key, *args)
383
- key = key.to_s
384
- if(_camel_keys && _camel_keys_action)
401
+ key = ::CamelString.new(key.to_s)
402
+ if(_camel_keys && _camel_keys_action && !key._hump_format_requested?)
385
403
  case _camel_keys_action
386
404
  when :auto_disable
387
405
  key._no_hump
@@ -394,10 +412,6 @@ class AttributeStruct < BasicObject
394
412
  "#{part[0,1].upcase}#{part[1,part.size]}"
395
413
  end.join.to_sym
396
414
  else
397
- if(_camel_keys)
398
- # Convert so Hash doesn't make a new one and lose the meta
399
- key = ::CamelString.new(key) unless key.is_a?(::CamelString)
400
- end
401
415
  key
402
416
  end
403
417
  end
@@ -430,6 +444,7 @@ class AttributeStruct < BasicObject
430
444
  def _camel_keys_set(v)
431
445
  @_camel_keys_set = v
432
446
  end
447
+ alias_method :camel_keys_set!, :_camel_keys_set
433
448
 
434
449
  # @return [Symbol, NilClass] :auto_disable or :auto_enable
435
450
  def _camel_keys_action
@@ -21,9 +21,13 @@ unless(defined?(MonkeyCamels))
21
21
  # Create a camel copy based on settings
22
22
  #
23
23
  # @return [String]
24
- def camel_initialize_copy(orig)
24
+ def camel_initialize_copy(orig, hump=nil)
25
25
  new_val = un_camel_initialize_copy(orig)
26
- orig._camel? ? new_val : new_val._no_hump
26
+ if(hump.nil?)
27
+ orig._camel? ? new_val : new_val._no_hump
28
+ else
29
+ new_val._no_hump if hump == false
30
+ end
27
31
  end
28
32
 
29
33
  # Provide string formatted based on hump setting
@@ -36,6 +40,11 @@ unless(defined?(MonkeyCamels))
36
40
 
37
41
  module Humps
38
42
 
43
+ # @return [TrueClass, FalseClass] specific style requested
44
+ def _hump_format_requested?
45
+ @__not_camel != nil
46
+ end
47
+
39
48
  # @return [TrueClass, FalseClass] camelized
40
49
  def _camel?
41
50
  !@__not_camel
@@ -46,12 +55,14 @@ unless(defined?(MonkeyCamels))
46
55
  @__not_camel = true
47
56
  self
48
57
  end
58
+ alias_method :disable_camel!, :_no_hump
49
59
 
50
60
  # @return [self] enable camelizing
51
61
  def _hump
52
62
  @__not_camel = false
53
63
  self
54
64
  end
65
+ alias_method :camel!, :_hump
55
66
 
56
67
  end
57
68
 
@@ -2,5 +2,5 @@ require 'attribute_struct/attribute_struct'
2
2
 
3
3
  class AttributeStruct
4
4
  # Current library version
5
- VERSION = ::Gem::Version.new('0.2.20')
5
+ VERSION = ::Gem::Version.new('0.2.22')
6
6
  end
@@ -1 +1,7 @@
1
- require 'attribute_struct/attribute_struct'
1
+
2
+ autoload :AttributeStruct, 'attribute_struct/attribute_struct'
3
+ autoload :MonkeyCamels, 'attribute_struct/monkey_camels'
4
+ autoload :CamelString, 'attribute_struct/monkey_camels'
5
+ autoload :IrbCompat, 'attribute_struct/irb_compat'
6
+
7
+ require 'attribute_struct/version'
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.20
4
+ version: 0.2.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-10 00:00:00.000000000 Z
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Attribute structures
14
14
  email: chrisroberts.code@gmail.com
@@ -52,3 +52,4 @@ signing_key:
52
52
  specification_version: 4
53
53
  summary: Attribute structures
54
54
  test_files: []
55
+ has_rdoc: