attribute_struct 0.4.2 → 0.4.4

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
- SHA1:
3
- metadata.gz: cfb863d08beb7bf41c350da383961c01f2bc0989
4
- data.tar.gz: fd2abc4187313555e34abfb97bb4b3e840bda142
2
+ SHA256:
3
+ metadata.gz: 0a111a3bd5eb4ca45c05040837630482f4f4e912955ab82fae427e1d2ee8a8c3
4
+ data.tar.gz: 9ce85d249bd59542e2eaf5946d145ee8250b54dfa57244fa812143818eea615f
5
5
  SHA512:
6
- metadata.gz: f734064ce0705b4df778bb9183e6d8a70eda70fa70923292e3ddd4dcf69942d55d39b7ab854761c371f08c28bfce870a9966ace91756898d80bd290f7c0f418d
7
- data.tar.gz: 47ea98e60b46b984f83edb14abc54baca279d7434125be0469b836b1b4b53f97eb5e58feb6549140744351b61327337d711467077d0fdbf083a1de17a3855752
6
+ metadata.gz: 0563f2b735ec6484e54beabc58a7a39051f90d6cf3997426ad06c4f5d1a010a22a79d9a858104cbfb49df29b479d2c1459bc73cac980ff2ad668c24c0a611779
7
+ data.tar.gz: ae4532589e7ba3136d342df0215ff35176b11a44d173e600521043788d9b66f3051a578d99402d1713945ee817c4c2934a8f4b9f2f2c3db08abe1f6fddf42fef
@@ -1,3 +1,6 @@
1
+ # v0.4.4
2
+ * Add `#key?` method to check for key existence
3
+
1
4
  # v0.4.2
2
5
  * Set cloned data via #_data on new instance
3
6
 
@@ -1,16 +1,19 @@
1
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
2
- require 'attribute_struct/version'
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + "/lib/"
2
+ require "attribute_struct/version"
3
3
  Gem::Specification.new do |s|
4
- s.name = 'attribute_struct'
4
+ s.name = "attribute_struct"
5
5
  s.version = AttributeStruct::VERSION.version
6
- s.summary = 'Attribute structures'
7
- s.author = 'Chris Roberts'
8
- s.license = 'Apache 2.0'
9
- s.email = 'chrisroberts.code@gmail.com'
10
- s.homepage = 'http://github.com/chrisroberts/attribute_struct'
11
- s.description = 'Attribute structures'
12
- s.require_path = 'lib'
13
- s.add_runtime_dependency 'bogo', '>= 0.1.31', '< 0.3.0'
14
- s.add_development_dependency 'minitest'
15
- s.files = Dir['lib/**/*'] + %w(attribute_struct.gemspec README.md CHANGELOG.md CONTRIBUTING.md LICENSE)
6
+ s.summary = "Attribute structures"
7
+ s.author = "Chris Roberts"
8
+ s.license = "Apache 2.0"
9
+ s.email = "chrisroberts.code@gmail.com"
10
+ s.homepage = "http://github.com/chrisroberts/attribute_struct"
11
+ s.description = "Attribute structures"
12
+ s.require_path = "lib"
13
+ s.add_runtime_dependency "bogo", ">= 0.1.31", "< 0.3.0"
14
+ s.add_development_dependency "rspec", "~> 3.5"
15
+ s.add_development_dependency "rake", "~> 10"
16
+ s.add_development_dependency "rufo", "~> 0.3.0"
17
+ s.add_development_dependency "minitest"
18
+ s.files = Dir["lib/**/*"] + %w(attribute_struct.gemspec README.md CHANGELOG.md CONTRIBUTING.md LICENSE)
16
19
  end
@@ -1,8 +1,8 @@
1
- require 'bogo'
2
- require 'attribute_struct/attribute_struct'
1
+ require "bogo"
2
+ require "attribute_struct/attribute_struct"
3
3
 
4
- autoload :MonkeyCamels, 'attribute_struct/monkey_camels'
5
- autoload :CamelString, 'attribute_struct/monkey_camels'
6
- autoload :IrbCompat, 'attribute_struct/irb_compat'
4
+ autoload :MonkeyCamels, "attribute_struct/monkey_camels"
5
+ autoload :CamelString, "attribute_struct/monkey_camels"
6
+ autoload :IrbCompat, "attribute_struct/irb_compat"
7
7
 
8
- require 'attribute_struct/version'
8
+ require "attribute_struct/version"
@@ -1,4 +1,4 @@
1
- require 'attribute_struct'
1
+ require "attribute_struct"
2
2
 
3
3
  class AttributeStruct
4
4
 
@@ -75,7 +75,7 @@ class AttributeStruct
75
75
  def initialize_copy(orig)
76
76
  super
77
77
  # Handle nested values
78
- each do |k,v|
78
+ each do |k, v|
79
79
  if v.kind_of?(Mash) || v.is_a?(Array)
80
80
  self[k] = v.dup
81
81
  end
@@ -150,7 +150,7 @@ class AttributeStruct
150
150
  #
151
151
  # @return [Array] The values at each of the provided keys
152
152
  def values_at(*indices)
153
- indices.collect {|key| self[convert_key(key)]}
153
+ indices.collect { |key| self[convert_key(key)] }
154
154
  end
155
155
 
156
156
  # @param hash<Hash> The hash to merge with the mash.
@@ -174,7 +174,7 @@ class AttributeStruct
174
174
  # { :one => 1, :two => 2, :three => 3 }.except(:one)
175
175
  # #=> { "two" => 2, "three" => 3 }
176
176
  def except(*keys)
177
- super(*keys.map {|k| convert_key(k)})
177
+ super(*keys.map { |k| convert_key(k) })
178
178
  end
179
179
 
180
180
  # Used to provide the same interface as Hash.
@@ -206,6 +206,7 @@ class AttributeStruct
206
206
  end
207
207
 
208
208
  protected
209
+
209
210
  # @param key<Object> The key to convert.
210
211
  #
211
212
  # @param [Object]
@@ -242,12 +243,12 @@ class AttributeStruct
242
243
  #
243
244
  # @return [AttributeStruct::Mash] merged hash
244
245
  def deep_merge(hash)
245
- unless(hash.is_a?(Hash))
246
+ unless (hash.is_a?(Hash))
246
247
  raise ArgumentError.new "Expecting `Hash` type. Received: `#{hash.class}`"
247
248
  end
248
249
  new_self = self.dup
249
- hash.each do |k,v|
250
- if(new_self[k].is_a?(Hash) && v.is_a?(Hash))
250
+ hash.each do |k, v|
251
+ if (new_self[k].is_a?(Hash) && v.is_a?(Hash))
251
252
  new_self[k] = new_self[k].deep_merge(v)
252
253
  else
253
254
  new_self[k] = v
@@ -263,7 +264,6 @@ class AttributeStruct
263
264
  self.replace(self.deep_merge(hash))
264
265
  self
265
266
  end
266
-
267
267
  end
268
268
 
269
269
  AttributeHash = Mash
@@ -1,9 +1,8 @@
1
- require 'attribute_struct'
1
+ require "attribute_struct"
2
2
 
3
3
  class AttributeStruct < BasicObject
4
-
5
- autoload :Augmented, 'attribute_struct/augmented'
6
- autoload :Mash, 'attribute_struct/attribute_hash'
4
+ autoload :Augmented, "attribute_struct/augmented"
5
+ autoload :Mash, "attribute_struct/attribute_hash"
7
6
 
8
7
  class << self
9
8
 
@@ -14,7 +13,7 @@ class AttributeStruct < BasicObject
14
13
  :no_leading => :no_leading,
15
14
  :dromedary => :leading,
16
15
  :leading_hump => :leading,
17
- :leading => :leading
16
+ :leading => :leading,
18
17
  }
19
18
 
20
19
  # @return [Truthy, Falsey] global flag for camel keys
@@ -46,17 +45,19 @@ class AttributeStruct < BasicObject
46
45
  # @return [Symbol]
47
46
  # @raises [ArgumentError]
48
47
  def validate_camel_style(style)
49
- if(VALID_CAMEL_STYLES.has_key?(style))
48
+ if (VALID_CAMEL_STYLES.has_key?(style))
50
49
  VALID_CAMEL_STYLES[style]
51
50
  else
52
- raise ArgumentError.new "Unsupported camel style provided `#{style.inspect}`! (Allowed: #{VALID_CAMEL_STYLES.keys(&:inspect).join(', ')})"
51
+ valid_types = VALID_CAMEL_STYLES.keys(&:inspect).join(", ")
52
+ raise ArgumentError.new "Unsupported camel style provided " \
53
+ "`#{style.inspect}`! (Allowed: #{valid_types})"
53
54
  end
54
55
  end
55
56
 
56
57
  # Loads helpers for camel casing
57
58
  def load_the_camels
58
- unless(@camels_loaded)
59
- require 'attribute_struct/monkey_camels'
59
+ unless (@camels_loaded)
60
+ require "attribute_struct/monkey_camels"
60
61
  @camels_loaded = true
61
62
  end
62
63
  end
@@ -68,7 +69,7 @@ class AttributeStruct < BasicObject
68
69
 
69
70
  # Create AttributeStruct instance and dump the resulting hash
70
71
  def build(&block)
71
- raise ArgumentError.new 'Block required for build!' unless block
72
+ raise ArgumentError.new "Block required for build!" unless block
72
73
  new(&block)._dump
73
74
  end
74
75
 
@@ -80,7 +81,6 @@ class AttributeStruct < BasicObject
80
81
  self.send(:include, IrbCompat)
81
82
  true
82
83
  end
83
-
84
84
  end
85
85
 
86
86
  # value used to identify unset value
@@ -103,15 +103,15 @@ class AttributeStruct < BasicObject
103
103
  #
104
104
  # @param init_hash [Hash] hash to initialize struct
105
105
  # @yield block to execute within struct context
106
- def initialize(init_hash=nil, &block)
106
+ def initialize(init_hash = nil, &block)
107
107
  @_camel_keys = _klass.camel_keys
108
108
  @_arg_state = __hashish.new
109
109
  @_objectified = false
110
110
  @table = __hashish.new
111
- if(init_hash)
111
+ if (init_hash)
112
112
  _load(init_hash)
113
113
  end
114
- if(block)
114
+ if (block)
115
115
  self.instance_exec(&block)
116
116
  end
117
117
  end
@@ -123,15 +123,17 @@ class AttributeStruct < BasicObject
123
123
  def _build(&block)
124
124
  self.instance_exec(&block)
125
125
  end
126
+
126
127
  alias_method :build!, :_build
127
128
 
128
129
  # Set state into current context
129
130
  #
130
131
  # @param args [Hashish] hashish type holding data for context
131
132
  # @return [Hashish]
132
- def _set_state(args={})
133
+ def _set_state(args = {})
133
134
  _arg_state.merge!(args)
134
135
  end
136
+
135
137
  alias_method :set_state!, :_set_state
136
138
 
137
139
  # Value of requested state
@@ -139,15 +141,16 @@ class AttributeStruct < BasicObject
139
141
  # @param key [Symbol, String]
140
142
  # @param traverse [TrueClass, FalseClass] traverse towards root for matching key
141
143
  # @return [Object, NilClass]
142
- def _state(key, traverse=true)
143
- if(_arg_state.has_key?(key))
144
+ def _state(key, traverse = true)
145
+ if (_arg_state.has_key?(key))
144
146
  _arg_state[key]
145
147
  else
146
- if(traverse && _parent)
148
+ if (traverse && _parent)
147
149
  _parent._state(key)
148
150
  end
149
151
  end
150
152
  end
153
+
151
154
  alias_method :state!, :_state
152
155
 
153
156
  # Enable/disable camel keys
@@ -171,9 +174,10 @@ class AttributeStruct < BasicObject
171
174
  #
172
175
  # @param enable [TrueClass, FalseClass]
173
176
  # @return [TrueClass, FalseClass]
174
- def _objectify(enable=true)
177
+ def _objectify(enable = true)
175
178
  @_objectified = !!enable
176
179
  end
180
+
177
181
  alias_method :objectify!, :_objectify
178
182
 
179
183
  # @return [TrueClass, FalseClass]
@@ -196,13 +200,14 @@ class AttributeStruct < BasicObject
196
200
  # @param val [Object]
197
201
  # @yield block to execute within context
198
202
  # @return [Object]
199
- def _set(key, val=UNSET_VALUE, &block)
200
- if(val != UNSET_VALUE)
203
+ def _set(key, val = UNSET_VALUE, &block)
204
+ if (val != UNSET_VALUE)
201
205
  self.method_missing(key, val, &block)
202
206
  else
203
207
  self.method_missing(key, &block)
204
208
  end
205
209
  end
210
+
206
211
  alias_method :set!, :_set
207
212
 
208
213
  # Provides struct DSL behavior
@@ -213,66 +218,66 @@ class AttributeStruct < BasicObject
213
218
  # @return [Object] existing value or newly set value
214
219
  # @note Dragons and unicorns all over in here
215
220
  def method_missing(_sym, *_args, &_block)
216
- if(objectified? && _args.empty? && _block.nil?)
221
+ if (objectified? && _args.empty? && _block.nil?)
217
222
  _o_lookup = _objectified_constant_lookup(_sym)
218
223
  return _o_lookup if _o_lookup
219
224
  end
220
- if(_sym.is_a?(::String) || _sym.is_a?(::Symbol))
221
- if((_s = _sym.to_s).end_with?('='))
225
+ if (_sym.is_a?(::String) || _sym.is_a?(::Symbol))
226
+ if ((_s = _sym.to_s).end_with?("="))
222
227
  _s.slice!(-1, _s.length)
223
228
  _sym = _s
224
229
  end
225
230
  _sym = _process_key(_sym)
226
231
  end
227
- if(!_args.empty? || _block)
228
- if(_args.empty? && _block)
232
+ if (!_args.empty? || _block)
233
+ if (_args.empty? && _block)
229
234
  _base = @table.fetch(_sym, UNSET_VALUE)
230
- if(_state(:value_collapse) && !_base.is_a?(self.class!))
235
+ if (_state(:value_collapse) && !_base.is_a?(self.class!))
231
236
  _orig = _base
232
237
  _base = _klass_new
233
238
  else
234
- unless(_base.is_a?(self.class!))
239
+ unless (_base.is_a?(self.class!))
235
240
  _base = _klass_new
236
241
  end
237
242
  end
238
243
  @table[_sym] = _base
239
- if(_block.arity == 0)
244
+ if (_block.arity == 0)
240
245
  _base.instance_exec(&_block)
241
246
  else
242
247
  _base.instance_exec(_base, &_block)
243
248
  end
244
- if(_orig.is_a?(::NilClass))
249
+ if (_orig.is_a?(::NilClass))
245
250
  @table[_sym] = _base
246
251
  else
247
- if(_orig == UNSET_VALUE)
252
+ if (_orig == UNSET_VALUE)
248
253
  @table[_sym] = _base
249
254
  else
250
- unless(_orig.is_a?(CollapseArray))
255
+ unless (_orig.is_a?(CollapseArray))
251
256
  _orig = CollapseArray.new.push(_orig)
252
257
  end
253
258
  _orig << _base
254
259
  @table[_sym] = _orig
255
260
  end
256
261
  end
257
- elsif(!_args.empty? && _block)
262
+ elsif (!_args.empty? && _block)
258
263
  _result = _leaf = _base = @table.fetch(_sym, _klass_new)
259
264
  @table[_sym] = _result
260
265
 
261
266
  _args.flatten.each do |_arg|
262
267
  _leaf = _base[_arg]
263
- unless(_leaf.is_a?(_klass))
268
+ unless (_leaf.is_a?(_klass))
264
269
  _leaf = _klass_new
265
270
  _base._set(_arg, _leaf)
266
271
  _base = _leaf
267
272
  end
268
273
  end
269
- if(!_leaf.nil? && _state(:value_collapse))
274
+ if (!_leaf.nil? && _state(:value_collapse))
270
275
  _orig = _leaf
271
276
  _leaf = _orig.parent._klass_new
272
277
  end
273
278
  _block.arity == 0 ? _leaf._build(&_block) : _leaf._build(_leaf, &_block)
274
- if(_orig)
275
- unless(_orig.is_a?(CollapseArray))
279
+ if (_orig)
280
+ unless (_orig.is_a?(CollapseArray))
276
281
  _orig = CollapseArray.new.push(_orig)
277
282
  end
278
283
  _orig << _leaf
@@ -280,19 +285,19 @@ class AttributeStruct < BasicObject
280
285
  _orig = _leaf
281
286
  end
282
287
  else
283
- if(_args.size > 1 && _args.all?{|_i| _i.is_a?(::String) || _i.is_a?(::Symbol)} && !_state(:value_collapse))
288
+ if (_args.size > 1 && _args.all? { |_i| _i.is_a?(::String) || _i.is_a?(::Symbol) } && !_state(:value_collapse))
284
289
  @table[_sym] = _klass_new unless @table[_sym].is_a?(_klass)
285
290
  _endpoint = _args.inject(@table[_sym]) do |_memo, _k|
286
- unless(_memo[_k].is_a?(_klass))
291
+ unless (_memo[_k].is_a?(_klass))
287
292
  _memo._set(_k, _klass_new)
288
293
  end
289
294
  _memo[_k]
290
295
  end
291
296
  return _endpoint # custom break out
292
297
  else
293
- if(_args.size > 1)
298
+ if (_args.size > 1)
294
299
  _val = _args.map do |_v|
295
- if(_v.is_a?(::Hash) && _state(:hash_load_struct))
300
+ if (_v.is_a?(::Hash) && _state(:hash_load_struct))
296
301
  _val = _klass_new
297
302
  _val._load(_v)
298
303
  else
@@ -300,15 +305,15 @@ class AttributeStruct < BasicObject
300
305
  end
301
306
  end
302
307
  else
303
- if(_args.first.is_a?(::Hash) && _state(:hash_load_struct))
308
+ if (_args.first.is_a?(::Hash) && _state(:hash_load_struct))
304
309
  _val = _klass_new
305
310
  _val._load(_args.first)
306
311
  else
307
312
  _val = _args.first
308
313
  end
309
314
  end
310
- if(_state(:value_collapse) && !(_leaf = @table[_sym]).nil?)
311
- unless(_leaf.is_a?(CollapseArray))
315
+ if (_state(:value_collapse) && !(_leaf = @table[_sym]).nil?)
316
+ unless (_leaf.is_a?(CollapseArray))
312
317
  _leaf = CollapseArray.new.push(_leaf)
313
318
  end
314
319
  _leaf << _val
@@ -340,18 +345,31 @@ class AttributeStruct < BasicObject
340
345
  def is_a?(klass)
341
346
  (_klass.ancestors + [::AttributeStruct]).include?(klass)
342
347
  end
348
+
343
349
  alias_method :kind_of?, :is_a?
344
350
 
351
+ # Check if key exists within struct
352
+ #
353
+ # @param key [String, Symbol]
354
+ # @return [TrueClass, FalseClass]
355
+ def key?(key)
356
+ self._keys.include?(_process_key(key))
357
+ end
358
+
359
+ alias_method :has_key?, :key?
360
+
345
361
  # @return [Array<String,Symbol>] keys within struct
346
362
  def _keys
347
363
  _data.keys
348
364
  end
365
+
349
366
  alias_method :keys!, :_keys
350
367
 
351
368
  # @return [AttributeStruct::AttributeHash, Mash] underlying struct data
352
369
  def _data
353
370
  @table
354
371
  end
372
+
355
373
  alias_method :data!, :_data
356
374
 
357
375
  # Delete entry from struct
@@ -361,6 +379,7 @@ class AttributeStruct < BasicObject
361
379
  def _delete(key)
362
380
  _data.delete(_process_key(key))
363
381
  end
382
+
364
383
  alias_method :delete!, :_delete
365
384
 
366
385
  # Process and unpack items for dumping within deeply nested
@@ -369,8 +388,8 @@ class AttributeStruct < BasicObject
369
388
  # @param item [Object]
370
389
  # @return [Object]
371
390
  def _dump_unpacker(item)
372
- if(item.is_a?(::Enumerable))
373
- if(item.respond_to?(:keys))
391
+ if (item.is_a?(::Enumerable))
392
+ if (item.respond_to?(:keys))
374
393
  item.class[
375
394
  *item.map do |entry|
376
395
  _dump_unpacker(entry)
@@ -383,7 +402,7 @@ class AttributeStruct < BasicObject
383
402
  end
384
403
  ]
385
404
  end
386
- elsif(item.is_a?(::AttributeStruct))
405
+ elsif (item.is_a?(::AttributeStruct))
387
406
  item.nil? ? UNSET_VALUE : item._dump
388
407
  else
389
408
  item
@@ -399,6 +418,7 @@ class AttributeStruct < BasicObject
399
418
  end.compact
400
419
  __hashish[*processed.flatten(1)]
401
420
  end
421
+
402
422
  alias_method :dump!, :_dump
403
423
 
404
424
  # Clear current struct data and replace
@@ -407,22 +427,22 @@ class AttributeStruct < BasicObject
407
427
  # @return [self]
408
428
  def _load(hashish)
409
429
  @table.clear
410
- if(_root._camel_keys_action == :auto_discovery)
411
- starts = hashish.keys.map{|k|k[0,1]}
412
- unless(starts.detect{|k| k =~ /[A-Z]/})
430
+ if (_root._camel_keys_action == :auto_discovery)
431
+ starts = hashish.keys.map { |k| k[0, 1] }
432
+ unless (starts.detect { |k| k =~ /[A-Z]/ })
413
433
  _camel_keys_set(:auto_disable)
414
434
  else
415
435
  _camel_keys_set(:auto_enable) unless _parent.nil?
416
436
  end
417
437
  end
418
438
  hashish.each do |key, value|
419
- if(value.is_a?(::Enumerable))
439
+ if (value.is_a?(::Enumerable))
420
440
  flat = value.map do |v|
421
441
  v.is_a?(::Hash) ? _klass_new(v) : v
422
442
  end
423
443
  value = value.is_a?(::Hash) ? __hashish[*flat.flatten(1)] : flat
424
444
  end
425
- if(value.is_a?(::Hash))
445
+ if (value.is_a?(::Hash))
426
446
  self._set(key)._load(value)
427
447
  else
428
448
  self._set(key, value)
@@ -430,6 +450,7 @@ class AttributeStruct < BasicObject
430
450
  end
431
451
  self
432
452
  end
453
+
433
454
  alias_method :load!, :_load
434
455
 
435
456
  # Perform deep merge
@@ -475,14 +496,14 @@ class AttributeStruct < BasicObject
475
496
  #
476
497
  # @param thing [Object] struct to copy. defaults to self
477
498
  # @return [Object] new instance
478
- def _deep_copy(thing=nil)
499
+ def _deep_copy(thing = nil)
479
500
  thing ||= _dump
480
- if(thing.is_a?(::Enumerable))
481
- val = thing.map{|v| v.is_a?(::Enumerable) ? _deep_copy(v) : _do_dup(v) }
501
+ if (thing.is_a?(::Enumerable))
502
+ val = thing.map { |v| v.is_a?(::Enumerable) ? _deep_copy(v) : _do_dup(v) }
482
503
  else
483
504
  val = _do_dup(thing)
484
505
  end
485
- if(thing.is_a?(::Hash))
506
+ if (thing.is_a?(::Hash))
486
507
  val = __hashish[*val.flatten(1)]
487
508
  end
488
509
  val
@@ -494,9 +515,9 @@ class AttributeStruct < BasicObject
494
515
  # @param args [Object] argument list (:force will force processing)
495
516
  # @return [String, Symbol]
496
517
  def _process_key(key, *args)
497
- if(key.is_a?(::String) || key.is_a?(::Symbol))
518
+ if (key.is_a?(::String) || key.is_a?(::Symbol))
498
519
  key = ::CamelString.new(key.to_s)
499
- if(_camel_keys && _camel_keys_action && !key._hump_format_requested?)
520
+ if (_camel_keys && _camel_keys_action && !key._hump_format_requested?)
500
521
  case _camel_keys_action
501
522
  when :auto_disable
502
523
  key._no_hump
@@ -504,10 +525,10 @@ class AttributeStruct < BasicObject
504
525
  key._hump
505
526
  end
506
527
  end
507
- if(_camel_keys && (key._camel? || args.include?(:force)))
528
+ if (_camel_keys && (key._camel? || args.include?(:force)))
508
529
  camel_args = [key]
509
- if(key._hump_style || _camel_style == :no_leading)
510
- unless(key._hump_style == :leading_hump)
530
+ if (key._hump_style || _camel_style == :no_leading)
531
+ unless (key._hump_style == :leading_hump)
511
532
  camel_args << false
512
533
  end
513
534
  end
@@ -519,6 +540,7 @@ class AttributeStruct < BasicObject
519
540
  key
520
541
  end
521
542
  end
543
+
522
544
  alias_method :process_key!, :_process_key
523
545
 
524
546
  # @return [Class] this class
@@ -530,6 +552,7 @@ class AttributeStruct < BasicObject
530
552
  def klass!
531
553
  _klass
532
554
  end
555
+
533
556
  alias_method :class!, :klass!
534
557
  alias_method :class, :klass!
535
558
 
@@ -537,7 +560,7 @@ class AttributeStruct < BasicObject
537
560
  # @note will set self as parent and propogate camelizing status
538
561
  def _klass_new(*args, &block)
539
562
  n = _klass.new(*args, &block)
540
- unless(_camel_keys_action == :auto_discovery)
563
+ unless (_camel_keys_action == :auto_discovery)
541
564
  n._camel_keys_set(_camel_keys_action)
542
565
  end
543
566
  n._camel_keys = _camel_keys
@@ -555,6 +578,7 @@ class AttributeStruct < BasicObject
555
578
  def _camel_keys_set(v)
556
579
  @_camel_keys_set = v
557
580
  end
581
+
558
582
  alias_method :camel_keys_set!, :_camel_keys_set
559
583
 
560
584
  # @return [Symbol, NilClass] :auto_disable or :auto_enable
@@ -563,20 +587,22 @@ class AttributeStruct < BasicObject
563
587
  end
564
588
 
565
589
  # @return [AttributeStruct, NilClass] parent of this struct
566
- def _parent(obj=nil)
590
+ def _parent(obj = nil)
567
591
  @_parent = obj if obj
568
592
  @_parent
569
593
  end
594
+
570
595
  alias_method :parent!, :_parent
571
596
 
572
597
  # @return [AttributeStruct, NilClass] root of the struct or nil if self is root
573
598
  def _root
574
599
  r = self
575
- until(r._parent == nil)
600
+ until (r._parent == nil)
576
601
  r = r._parent
577
602
  end
578
603
  r
579
604
  end
605
+
580
606
  alias_method :root!, :_root
581
607
 
582
608
  # Create an Array and evaluate discovered AttributeStructs
@@ -585,9 +611,9 @@ class AttributeStruct < BasicObject
585
611
  # @return [Array]
586
612
  def _array(*args)
587
613
  args.map do |maybe_block|
588
- if(maybe_block.is_a?(::Proc))
614
+ if (maybe_block.is_a?(::Proc))
589
615
  klass = _klass_new
590
- if(maybe_block.arity > 0)
616
+ if (maybe_block.arity > 0)
591
617
  klass.instance_exec(klass, &maybe_block)
592
618
  else
593
619
  klass.instance_exec(&maybe_block)
@@ -598,6 +624,7 @@ class AttributeStruct < BasicObject
598
624
  end
599
625
  end
600
626
  end
627
+
601
628
  alias_method :array!, :_array
602
629
 
603
630
  # Instance responds to method name
@@ -613,7 +640,7 @@ class AttributeStruct < BasicObject
613
640
  # @param konst [Symbol, String]
614
641
  # @return [Object, NilClass]
615
642
  def _objectified_constant_lookup(konst)
616
- if(konst.to_s[0].match(/[A-Z]/) && ::Object.const_defined?(konst))
643
+ if (konst.to_s[0].match(/[A-Z]/) && ::Object.const_defined?(konst))
617
644
  ::Object.const_get(konst)
618
645
  end
619
646
  end
@@ -622,7 +649,7 @@ class AttributeStruct < BasicObject
622
649
  #
623
650
  # @return [TrueClass]
624
651
  def _kernelify
625
- unless(kernelified?)
652
+ unless (kernelified?)
626
653
  @_kernelified = true
627
654
  (::Kernel.public_instance_methods + ::Kernel.private_instance_methods).each do |m_name|
628
655
  self.instance_eval("def #{m_name}(*a, &b); ::Kernel.instance_method(:#{m_name}).bind(self).curry.call(*a, &b); end")
@@ -630,6 +657,7 @@ class AttributeStruct < BasicObject
630
657
  end
631
658
  true
632
659
  end
660
+
633
661
  alias_method :kernelify!, :_kernelify
634
662
 
635
663
  # @return [TrueClass, FalseClass] Kernel methods have been injected
@@ -643,28 +671,29 @@ class AttributeStruct < BasicObject
643
671
  end
644
672
 
645
673
  # @return [AttributeStruct] clone of current instance
646
- def _clone(_new_parent=nil)
674
+ def _clone(_new_parent = nil)
647
675
  _cloned_inst = _klass_new
648
676
  _cloned_inst._data.replace __hashish[
649
- @table.map{ |_key, _value|
650
- if(_key.is_a?(::AttributeStruct))
651
- _key = _key._clone
652
- else
653
- _key = _do_dup(_key)
654
- end
655
- if(_value.is_a?(::AttributeStruct))
656
- _value = _value._clone
657
- else
658
- _value = _do_dup(_value)
659
- end
660
- [_key, _value]
661
- }
662
- ]
677
+ @table.map { |_key, _value|
678
+ if (_key.is_a?(::AttributeStruct))
679
+ _key = _key._clone
680
+ else
681
+ _key = _do_dup(_key)
682
+ end
683
+ if (_value.is_a?(::AttributeStruct))
684
+ _value = _value._clone
685
+ else
686
+ _value = _do_dup(_value)
687
+ end
688
+ [_key, _value]
689
+ }
690
+ ]
663
691
  _cloned_inst._parent(_new_parent) if _new_parent
664
692
  _cloned_inst
665
693
  end
694
+
666
695
  alias_method :clone!, :_clone
667
696
  end
668
697
 
669
- require 'attribute_struct/attribute_hash'
670
- require 'attribute_struct/version'
698
+ require "attribute_struct/attribute_hash"
699
+ require "attribute_struct/version"
@@ -1,10 +1,9 @@
1
- require 'attribute_struct'
1
+ require "attribute_struct"
2
2
 
3
3
  class AttributeStruct
4
4
  # AttributeStruct expanded class that include the Kernel module
5
5
  # and automatically objectifies the instance
6
6
  class Augmented < ::AttributeStruct
7
-
8
7
  include ::Kernel
9
8
 
10
9
  # Create a new Augmented AttributeStruct instance. Passes arguments
@@ -21,6 +20,5 @@ class AttributeStruct
21
20
  def _klass
22
21
  ::AttributeStruct::Augmented
23
22
  end
24
-
25
23
  end
26
24
  end
@@ -10,5 +10,4 @@ module IrbCompat
10
10
  def to_s
11
11
  "<#{self._klass}:#{@table.object_id}>"
12
12
  end
13
-
14
13
  end
@@ -1,13 +1,10 @@
1
- require 'attribute_struct'
2
-
3
- unless(defined?(MonkeyCamels))
1
+ require "attribute_struct"
4
2
 
3
+ unless (defined?(MonkeyCamels))
5
4
  module MonkeyCamels
6
-
7
5
  class << self
8
6
  def included(klass)
9
7
  klass.class_eval do
10
-
11
8
  include Humps
12
9
 
13
10
  alias_method :un_camel_to_s, :to_s
@@ -21,9 +18,9 @@ unless(defined?(MonkeyCamels))
21
18
  # Create a camel copy based on settings
22
19
  #
23
20
  # @return [String]
24
- def camel_initialize_copy(orig, hump=nil)
21
+ def camel_initialize_copy(orig, hump = nil)
25
22
  new_val = un_camel_initialize_copy(orig)
26
- if(hump.nil?)
23
+ if (hump.nil?)
27
24
  orig._camel? ? new_val : new_val._no_hump
28
25
  else
29
26
  new_val._no_hump if hump == false
@@ -55,6 +52,7 @@ unless(defined?(MonkeyCamels))
55
52
  @__not_camel = true
56
53
  self
57
54
  end
55
+
58
56
  alias_method :disable_camel!, :_no_hump
59
57
 
60
58
  # @return [self] enable camelizing
@@ -62,12 +60,14 @@ unless(defined?(MonkeyCamels))
62
60
  @__not_camel = false
63
61
  self
64
62
  end
63
+
65
64
  alias_method :camel!, :_hump
66
65
 
67
66
  # @return [Symbol, NilClass] style of hump
68
67
  def _hump_style
69
68
  @__hump_style
70
69
  end
70
+
71
71
  alias_method :hump_style!, :_hump_style
72
72
 
73
73
  # Set hump style to non-leading upcase
@@ -78,6 +78,7 @@ unless(defined?(MonkeyCamels))
78
78
  @__hump_style = :no_leading_hump
79
79
  self
80
80
  end
81
+
81
82
  alias_method :bactrian!, :_bactrian
82
83
  alias_method :no_leading_hump!, :_bactrian
83
84
 
@@ -89,11 +90,10 @@ unless(defined?(MonkeyCamels))
89
90
  @__hump_style = :leading_hump
90
91
  self
91
92
  end
93
+
92
94
  alias_method :dromedary!, :_dromedary
93
95
  alias_method :leading_hump!, :_dromedary
94
-
95
96
  end
96
-
97
97
  end
98
98
 
99
99
  # Force some monkeys around
@@ -102,13 +102,12 @@ unless(defined?(MonkeyCamels))
102
102
 
103
103
  # Specialized String type
104
104
  class CamelString < String
105
- def initialize(val=nil)
105
+ def initialize(val = nil)
106
106
  super
107
- if(val.respond_to?(:_camel?))
107
+ if (val.respond_to?(:_camel?))
108
108
  _no_hump unless val._camel?
109
109
  @__hump_style = val._hump_style
110
110
  end
111
111
  end
112
112
  end
113
-
114
113
  end
@@ -1,4 +1,4 @@
1
1
  class AttributeStruct < BasicObject
2
2
  # Current library version
3
- VERSION = ::Gem::Version.new('0.4.2')
3
+ VERSION = ::Gem::Version.new("0.4.4")
4
4
  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.4.2
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-11 00:00:00.000000000 Z
11
+ date: 2018-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bogo
@@ -30,6 +30,48 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.3.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.5'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.5'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rufo
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.3.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.3.0
33
75
  - !ruby/object:Gem::Dependency
34
76
  name: minitest
35
77
  requirement: !ruby/object:Gem::Requirement
@@ -82,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
124
  version: '0'
83
125
  requirements: []
84
126
  rubyforge_project:
85
- rubygems_version: 2.4.8
127
+ rubygems_version: 2.7.6
86
128
  signing_key:
87
129
  specification_version: 4
88
130
  summary: Attribute structures