codecode-common-utils 0.1.4 → 0.1.5
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/lib/codecode/common/utils.rb +45 -7
- data/lib/codecode/common/utils/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0be9a41ed883d1a742c1c9fab22eacdf7720b74c
|
4
|
+
data.tar.gz: 3b6969826d1fd734d65f63acb2f2906d108ace76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eafe0bef68ec71475a90d3ada4a9eb7df533e418a13ee48dc7b3ee3dd29bb3307ca686d842da4c993c91cf2c2ea30a585441ecf99d5253a618abaec1b0af113c
|
7
|
+
data.tar.gz: 7dc9090f1c5cf4cb6106656cddff0b9743c24692f098bd7c458dd53433ae1aaa50dffbc56332bb0abb9f090c8739332f4bd25e9dc239e8e3b2db9f2f26ffbce7
|
@@ -13,10 +13,14 @@ module CodeCode
|
|
13
13
|
#
|
14
14
|
# @param [Hash] hash
|
15
15
|
# @return [Hash] The resulting hash with symbolized keys
|
16
|
-
def
|
16
|
+
def symbolize_keys(hash)
|
17
17
|
hash.inject({}){ |memo, (k, v)|
|
18
18
|
memo[k.to_sym] = v
|
19
|
-
|
19
|
+
if v.class.eql? ::Hash
|
20
|
+
memo[k.to_sym] = symbolize_keys v
|
21
|
+
elsif v.class.eql? ::Array
|
22
|
+
memo[k.to_sym] = symbolize_keys_of_hashs v
|
23
|
+
end
|
20
24
|
memo
|
21
25
|
}
|
22
26
|
end
|
@@ -25,21 +29,55 @@ module CodeCode
|
|
25
29
|
#
|
26
30
|
# @param [Hash] hash
|
27
31
|
# @return [Hash] The resulting hash with symbolized keys
|
28
|
-
def
|
32
|
+
def symbolize_keys!(hash)
|
29
33
|
new_hash = hash.inject({}){ |memo, (k, v)|
|
30
34
|
memo[k.to_sym] = v
|
31
|
-
|
35
|
+
if v.class.eql? ::Hash
|
36
|
+
memo[k.to_sym] = symbolize_keys! v
|
37
|
+
elsif v.class.eql? ::Array
|
38
|
+
memo[k.to_sym] = symbolize_keys_of_hashs! v
|
39
|
+
end
|
32
40
|
memo
|
33
41
|
}
|
34
42
|
hash.replace new_hash
|
35
43
|
end
|
36
44
|
|
45
|
+
# Convert Hash Array with string keys to symbol keys
|
46
|
+
# @param [Object] array_of_hashs Array of String Hash
|
47
|
+
# @return [Object] Array of Symbol Hash
|
48
|
+
def symbolize_keys_of_hashs(array_of_hashs)
|
49
|
+
array_of_hashs.collect{|hash| symbolize_keys(hash)}
|
50
|
+
end
|
51
|
+
|
52
|
+
# BANG! Convert Hash Array with string keys to symbol keys
|
53
|
+
# @param [Object] array_of_hashs Array of String Hash
|
54
|
+
# @return [Object] Array of Symbol Hash
|
55
|
+
def symbolize_keys_of_hashs!(array_of_hashs)
|
56
|
+
array_of_hashs.collect!{|hash| symbolize_keys(hash)}
|
57
|
+
end
|
58
|
+
|
59
|
+
def recursive_key_symbolizer!(object)
|
60
|
+
if object.class.eql? ::Array
|
61
|
+
symbolize_keys_of_hashs! object
|
62
|
+
elsif object.class.eql? ::Hash
|
63
|
+
symbolize_keys! object
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def recursive_key_symbolizer(object)
|
68
|
+
if object.class.eql? ::Array
|
69
|
+
symbolize_keys_of_hashs object
|
70
|
+
elsif object.class.eql? ::Hash
|
71
|
+
symbolize_keys object
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
37
75
|
# Removes a key from the hash and return the modified hash
|
38
76
|
#
|
39
77
|
# @param [Hash] hash
|
40
78
|
# @param [Symbol] key
|
41
79
|
# @return [Hash] The given hash without the removed key
|
42
|
-
def
|
80
|
+
def except(hash, key)
|
43
81
|
hash.delete(key)
|
44
82
|
end
|
45
83
|
|
@@ -48,7 +86,7 @@ module CodeCode
|
|
48
86
|
# @param [Hash] hash
|
49
87
|
# @param [Array] keys
|
50
88
|
# @return [Hash]
|
51
|
-
def
|
89
|
+
def select(hash, keys)
|
52
90
|
hash.select { |k, v| keys.include?(k) }
|
53
91
|
end
|
54
92
|
end
|
@@ -60,7 +98,7 @@ module CodeCode
|
|
60
98
|
# empty or keys are missing
|
61
99
|
# @param [Array[Symbol]] required_fields array of symbols
|
62
100
|
# @param [Object] params
|
63
|
-
def
|
101
|
+
def check_fields(required_fields, params)
|
64
102
|
required_fields, missing, empty, null = required_fields, [], [], []
|
65
103
|
required_fields.each { |key|
|
66
104
|
missing.push(key) unless params.keys.include?(key)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codecode-common-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felipe Rodrigues Michetti
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|