active_object 4.0.7 → 4.0.8
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/README.md +19 -3
- data/lib/active_object/hash.rb +14 -0
- data/lib/active_object/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fc08a3fb5836a6f154a0f1d7854cdafd68dfcea
|
4
|
+
data.tar.gz: 7deb7107836576302250d73656aaf4c0dd9eccb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d22be40f8fbe844dc638f0d265d03746816850fe2e1e5484ee67fe8131123588c232470f7d14afb96c3498bc3dfe01e632103c195b2384bd92024fdc5ab0f571
|
7
|
+
data.tar.gz: cc1543d95b6ca3a04b422ba207ef4af2e7c1700aab01d962953dd7a140e92eb91fc8635421d939d03a472b160af0d5c5e4b5e69bdc3adda3003672e6807cfff6
|
data/README.md
CHANGED
@@ -459,6 +459,22 @@ end
|
|
459
459
|
{ foo: 'bar', baz: 'boz' }.assert_valid_keys(:foo, :boo) #=> raises 'ArgumentError: Unknown key: :baz. Valid keys are: :foo, :boo'
|
460
460
|
```
|
461
461
|
|
462
|
+
**Collect Keys:**
|
463
|
+
`collect_keys` returns an array with all keys converted using the block operation.
|
464
|
+
|
465
|
+
```ruby
|
466
|
+
{ foo: 'bar', 'baz' => :boo }.collect_keys #=> [:foo, 'baz']
|
467
|
+
{ foo: 'bar', 'baz' => :boo }.collect_keys { |k| k.to_s.upcase } #=> ['FOO', BAZ']
|
468
|
+
```
|
469
|
+
|
470
|
+
**Collect Values:**
|
471
|
+
`collect_values` returns an array with all values converted using the block operation.
|
472
|
+
|
473
|
+
```ruby
|
474
|
+
{ foo: 'bar', baz: :boo }.collect_values #=> ['bar', :boo]
|
475
|
+
{ foo: 'bar', baz: :boo }.collect_values { |k| k.to_s.upcase } #=> ['BAR', BOO']
|
476
|
+
```
|
477
|
+
|
462
478
|
**Compact:**
|
463
479
|
`compact` and `compact!` returns a hash with non nil values.
|
464
480
|
|
@@ -581,7 +597,7 @@ h.shuffle! #=> { d: 4, b: 2, c: 3, a: 1 }
|
|
581
597
|
```
|
582
598
|
|
583
599
|
**Slice:**
|
584
|
-
`slice` a hash to include only the given keys. Returns a hash containing the given keys.
|
600
|
+
`slice` returns a hash to include only the given keys. Returns a hash containing the given keys.
|
585
601
|
`slice!` replaces the hash with only the given keys. Returns a hash containing the removed key/value pairs.
|
586
602
|
|
587
603
|
```ruby
|
@@ -622,14 +638,14 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
622
638
|
```
|
623
639
|
|
624
640
|
**Transform Keys:**
|
625
|
-
`transform_keys` and `transform_keys!` a new hash with all keys converted using the block operation.
|
641
|
+
`transform_keys` and `transform_keys!` returns a new hash with all keys converted using the block operation.
|
626
642
|
|
627
643
|
```ruby
|
628
644
|
{ foo: 'bar', baz: 'boo' }.transform_keys { |k| k.to_s.upcase } #=> { 'FOO' => 'bar', 'BAZ' => 'boo' }
|
629
645
|
```
|
630
646
|
|
631
647
|
**Transform Values:**
|
632
|
-
`transform_values` and `transform_values!` a new hash with all values converted using the block operation.
|
648
|
+
`transform_values` and `transform_values!` returns a new hash with all values converted using the block operation.
|
633
649
|
|
634
650
|
```ruby
|
635
651
|
{ foo: 'bar', baz: 'boo' }.transform_values { |v| v.to_s.upcase } #=> {foo: 'BAR', baz: 'BOO' }
|
data/lib/active_object/hash.rb
CHANGED
@@ -28,6 +28,20 @@ module ActiveObject::Hash
|
|
28
28
|
reject! { |_, val| val.nil? }
|
29
29
|
end
|
30
30
|
|
31
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
32
|
+
def collect_keys(&block)
|
33
|
+
return(enum_for(:collect_keys)) unless block_given?
|
34
|
+
|
35
|
+
collect { |key, _| yield(key) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def collect_values(&block)
|
39
|
+
return(enum_for(:collect_values)) unless block_given?
|
40
|
+
|
41
|
+
collect { |_, val| yield(val) }
|
42
|
+
end
|
43
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
44
|
+
|
31
45
|
def deep_merge(other_hash, &block)
|
32
46
|
dup.deep_merge!(other_hash, yield(block))
|
33
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|
@@ -197,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
197
|
version: '0'
|
198
198
|
requirements: []
|
199
199
|
rubyforge_project:
|
200
|
-
rubygems_version: 2.6.
|
200
|
+
rubygems_version: 2.6.12
|
201
201
|
signing_key:
|
202
202
|
specification_version: 4
|
203
203
|
summary: Gem for commonly used ruby object helpers.
|