nrser 0.0.28 → 0.0.29

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: 85d9f96689536eea53d1334428dc1a1b5ba14d63
4
- data.tar.gz: 773bcdf4b40c0eca5b89e12a4e0a08f2da3de1e6
3
+ metadata.gz: 2273f6424356766a1849b35fc437b13942f15af1
4
+ data.tar.gz: 901f479555218cc42909235832f2271ca8f61579
5
5
  SHA512:
6
- metadata.gz: e1bc880e2be168415407889bfe879580c4ac2e3434535c18e82d55a023cf8147f80edcc0beff71cfc148c12a0b5a10368180c2f27990626d55db7a79399d2b71
7
- data.tar.gz: 84ab4489ab336f867075a34103a20fabb9f7d626bae7d2aea4139fb1582e6fc2ce322d86fbb7cb2667f76b317e8e3aee3a4ad9984c280f88026fef3cb3af52eb
6
+ metadata.gz: 87482595ba0e8a8fec1b3e7c3b3c368432a5edbef62a2704d721e61199177446a6d0e28ca4c2f1119db5d7adb8da8666ded661f3c79f20f44dbccee48b756e80
7
+ data.tar.gz: 412d7fdbe26337164955f5a52e6bc70370f2bd5c1282797e66c91b794fa2b8471e2dc9865e9210b822490799194a90102242466967e233a23630f773ac6cf33b
@@ -16,7 +16,7 @@ module NRSER
16
16
  transform_keys! hash, &:to_s
17
17
  end
18
18
 
19
- singleton_class.send :alias_method, :str_keys!, :stringify_keys!
19
+ singleton_class.send :alias_method, :to_s_keys!, :stringify_keys!
20
20
 
21
21
 
22
22
  # Returns a new hash with all keys transformed to strings by calling `#to_s`
@@ -32,6 +32,22 @@ module NRSER
32
32
  transform_keys hash, &:to_s
33
33
  end
34
34
 
35
- singleton_class.send :alias_method, :str_keys, :stringify_keys
35
+ singleton_class.send :alias_method, :to_s_keys, :stringify_keys
36
+
37
+
38
+ # @todo Document deep_stringify_keys method.
39
+ #
40
+ # @param [type] arg_name
41
+ # @todo Add name param description.
42
+ #
43
+ # @return [return_type]
44
+ # @todo Document return value.
45
+ #
46
+ def self.deep_stringify_keys object
47
+ deep_transform_keys object, &:to_s
48
+ end # .deep_stringify_keys
49
+
50
+ singleton_class.send :alias_method, :to_s_keys_r, :deep_stringify_keys
51
+
36
52
 
37
53
  end # module NRSER
@@ -17,7 +17,7 @@ module NRSER
17
17
  transform_keys!(hash) { |key| key.to_sym rescue key }
18
18
  end # .symbolize_keys!
19
19
 
20
- singleton_class.send :alias_method, :sym_keys!, :symbolize_keys!
20
+ singleton_class.send :alias_method, :to_sym_keys!, :symbolize_keys!
21
21
 
22
22
 
23
23
  # Returns a new hash with all keys that respond to `#to_sym` converted to
@@ -36,6 +36,20 @@ module NRSER
36
36
  transform_keys(hash) { |key| key.to_sym rescue key }
37
37
  end
38
38
 
39
- singleton_class.send :alias_method, :sym_keys, :symbolize_keys
39
+ singleton_class.send :alias_method, :to_sym_keys, :symbolize_keys
40
+
41
+
42
+ # @todo Document deep_symbolize_keys method.
43
+ #
44
+ # @param [type] arg_name
45
+ # @todo Add name param description.
46
+ #
47
+ # @return [return_type]
48
+ # @todo Document return value.
49
+ #
50
+ def self.deep_symbolize_keys object, &block
51
+ deep_transform_keys( object ) { key.to_sym rescue key }
52
+ end # .deep_symbolize_keys
53
+
40
54
 
41
55
  end # module NRSER
@@ -39,7 +39,100 @@ module NRSER
39
39
  result
40
40
  end
41
41
 
42
- # My-style name
43
- singleton_class.send :alias_method, :map_keys, :transform_keys
42
+ # My-style names
43
+ singleton_class.send :alias_method, :map_keys, :transform_keys
44
+ singleton_class.send :alias_method, :rekey, :transform_keys
45
+
46
+
47
+ # Deeply transform Hash keys that we can find by traversing Hash and Array
48
+ # instances that we can find from `object` and piping keys through `block`.
49
+ #
50
+ # @example Hash top node
51
+ #
52
+ # NRSER.deep_transform_keys({
53
+ # people: {
54
+ # jane: {fav_color: 'red'},
55
+ # joe: {fav_color: 'blue'},
56
+ # }
57
+ # }) { |key| key.to_s.upcase }
58
+ # # => {
59
+ # # "PEOPLE" => {
60
+ # # "JANE" => {"FAV_COLOR" => 'red'},
61
+ # # "JOE" => {"FAV_COLOR" => 'blue'},
62
+ # # }
63
+ #
64
+ # @example Array top node
65
+ #
66
+ # NRSER.deep_transform_keys(
67
+ # [{x: 2}, {y: 'blue'}, 3]
68
+ # ) { |key| key.to_s.upcase }
69
+ # # => [{'X' => 2}, {'Y' => 'blue'}, 3]
70
+ #
71
+ #
72
+ # @example Non-array or hash value
73
+ #
74
+ # NRSER.deep_transform_keys 'blah'
75
+ # # => 'blah'
76
+ #
77
+ # From ActiveSupport.
78
+ #
79
+ # @see http://www.rubydoc.info/gems/activesupport/5.1.3/Hash:deep_transform_keys
80
+ #
81
+ # @todo Maybe this is a tree function?
82
+ #
83
+ # @param [Object] object
84
+ # Anything; see examples.
85
+ #
86
+ # @param [Proc] &block
87
+ # Proc that should accept each key as it's only argument and return the
88
+ # new key to replace it with.
89
+ #
90
+ def self.deep_transform_keys object, &block
91
+ case object
92
+ when Hash
93
+ object.each_with_object( {} ) do |(key, value), result|
94
+ result[block.call( key )] = deep_transform_keys value, &block
95
+ end
96
+ when Array
97
+ object.map { |entry| deep_transform_keys entry, &block }
98
+ else
99
+ object
100
+ end
101
+ end
102
+
103
+ singleton_class.send :alias_method, :deep_map_keys, :deep_transform_keys
104
+ singleton_class.send :alias_method, :map_keys_r, :deep_transform_keys
105
+ singleton_class.send :alias_method, :deep_rekey, :deep_transform_keys
106
+ singleton_class.send :alias_method, :rekey_r, :deep_transform_keys
107
+
108
+
109
+ # Like {NRSER.deep_transform_keys} but mutates the objects (works in place).
110
+ #
111
+ # @param object (see NRSER.deep_transform_keys)
112
+ # @param &block (see NRSER.deep_transform_keys)
113
+ #
114
+ # @return [Object]
115
+ # The `object` that was passed in, post mutations.
116
+ #
117
+ def self.deep_transform_keys! object, &block
118
+ case object
119
+ when Hash
120
+ object.keys.each do |key|
121
+ value = object.delete key
122
+ object[block.call( key )] = deep_transform_keys! value, &block
123
+ end
124
+ object
125
+ when Array
126
+ object.map! {|e| deep_transform_keys!(e, &block)}
127
+ else
128
+ object
129
+ end
130
+ end
131
+
132
+ singleton_class.send :alias_method, :deep_map_keys!, :deep_transform_keys!
133
+ singleton_class.send :alias_method, :map_keys_r!, :deep_transform_keys!
134
+ singleton_class.send :alias_method, :deep_rekey!, :deep_transform_keys!
135
+ singleton_class.send :alias_method, :rekey_r!, :deep_transform_keys!
136
+
44
137
 
45
138
  end # module NRSER
@@ -46,13 +46,37 @@ module NRSER
46
46
  end
47
47
 
48
48
 
49
+ # See {NRSER.deep_transform_keys!}
50
+ def deep_transform_keys! &block
51
+ return enum_for(:deep_transform_keys!) { size } unless block_given?
52
+ NRSER.deep_transform_keys! self, &block
53
+ end
54
+
55
+ alias_method :deep_map_keys!, :deep_transform_keys!
56
+ alias_method :map_keys_r!, :deep_transform_keys!
57
+ alias_method :deep_rekey!, :deep_transform_keys!
58
+ alias_method :rekey_r!, :deep_transform_keys!
59
+
60
+
49
61
  # See {NRSER.transform_keys}
50
62
  def transform_keys &block
51
- return hash.enum_for(:transform_keys) { size } unless block_given?
63
+ return enum_for(:transform_keys) { size } unless block_given?
52
64
  NRSER.transform_keys self, &block
53
65
  end
54
66
 
55
67
 
68
+ # See {NRSER.deep_transform_keys}
69
+ def deep_transform_keys &block
70
+ return enum_for(:deep_transform_keys) { size } unless block_given?
71
+ NRSER.deep_transform_keys self, &block
72
+ end
73
+
74
+ alias_method :deep_map_keys, :deep_transform_keys
75
+ alias_method :map_keys_r, :deep_transform_keys
76
+ alias_method :deep_rekey, :deep_transform_keys
77
+ alias_method :rekey_r, :deep_transform_keys
78
+
79
+
56
80
  # See {NRSER.symbolize_keys!}
57
81
  def symbolize_keys!
58
82
  NRSER.symbolize_keys! self
data/lib/nrser/rspex.rb CHANGED
@@ -269,7 +269,7 @@ module NRSER::RSpex
269
269
 
270
270
  describe description, **metadata, type: type do
271
271
  subject( &subject_block ) if subject_block
272
- instance_exec &body
272
+ module_exec &body
273
273
  end # description,
274
274
 
275
275
  end # #describe_x
@@ -336,7 +336,7 @@ module NRSER::RSpex
336
336
 
337
337
  describe description, type: :message do
338
338
  subject { NRSER::Message.new symbol, *args }
339
- instance_exec &body
339
+ module_exec &body
340
340
  end
341
341
  end
342
342
 
@@ -364,7 +364,7 @@ module NRSER::RSpex
364
364
 
365
365
  describe "sent to #{ receiver } (#{ mode })" do
366
366
  subject { super().send_to unwrap( receiver, context: self ) }
367
- instance_exec &block
367
+ module_exec &block
368
368
  end
369
369
  end # #describe_sent_to
370
370
 
@@ -382,7 +382,7 @@ module NRSER::RSpex
382
382
 
383
383
  describe "return value from #{ msg }" do
384
384
  subject { msg.send_to super() }
385
- instance_exec &body
385
+ module_exec &body
386
386
  end # "return value from #{ msg }"
387
387
  end
388
388
 
@@ -413,7 +413,7 @@ module NRSER::RSpex
413
413
  type: :section,
414
414
  **metadata
415
415
  ) do
416
- instance_exec &block
416
+ module_exec &block
417
417
  end
418
418
  end # #describe_section
419
419
 
@@ -430,7 +430,7 @@ module NRSER::RSpex
430
430
  file: path,
431
431
  **metadata
432
432
  ) do
433
- instance_exec &body
433
+ module_exec &body
434
434
  end
435
435
  end
436
436
 
@@ -441,7 +441,7 @@ module NRSER::RSpex
441
441
  type: :module,
442
442
  **metadata
443
443
  ) do
444
- instance_exec &block
444
+ module_exec &block
445
445
  end
446
446
  end # #describe_module
447
447
 
@@ -459,7 +459,7 @@ module NRSER::RSpex
459
459
  subject { klass }
460
460
  end
461
461
 
462
- instance_exec &block
462
+ module_exec &block
463
463
  end
464
464
  end # #describe_class
465
465
 
@@ -475,7 +475,7 @@ module NRSER::RSpex
475
475
  type: :group,
476
476
  **metadata
477
477
  ) do
478
- instance_exec &block
478
+ module_exec &block
479
479
  end
480
480
  end # #describe_class
481
481
 
@@ -491,7 +491,7 @@ module NRSER::RSpex
491
491
  subject { super().method name }
492
492
  end
493
493
 
494
- instance_exec &block
494
+ module_exec &block
495
495
  end
496
496
  end # #describe_method
497
497
 
@@ -503,7 +503,7 @@ module NRSER::RSpex
503
503
  **metadata
504
504
  ) do
505
505
  subject { super().public_send symbol }
506
- instance_exec &block
506
+ module_exec &block
507
507
  end
508
508
  end # #describe_attribute
509
509
 
@@ -536,7 +536,7 @@ module NRSER::RSpex
536
536
  let( name ) { unwrap value, context: self }
537
537
  }
538
538
 
539
- instance_exec &body
539
+ module_exec &body
540
540
  end
541
541
  end
542
542
 
data/lib/nrser/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module NRSER
2
- VERSION = "0.0.28"
2
+ VERSION = "0.0.29"
3
3
 
4
4
  module Version
5
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nrser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.28
4
+ version: 0.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-06 00:00:00.000000000 Z
11
+ date: 2017-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -295,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
295
295
  version: '0'
296
296
  requirements: []
297
297
  rubyforge_project:
298
- rubygems_version: 2.6.11
298
+ rubygems_version: 2.5.2
299
299
  signing_key:
300
300
  specification_version: 4
301
301
  summary: basic ruby utils i use in a lot of stuff.