active_object 5.4.0 → 5.5.0
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 +10 -2
- data/lib/active_object/kernel.rb +9 -0
- data/lib/active_object/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23b7700dd3c7bd5a4061ae502428e076fde80119f753df4e8c5a9833a9e0251a
|
4
|
+
data.tar.gz: c91137e38e5ce476f0f7e9cb4121eed00734c109b7050bd9218afa2e08c4655b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fd8511611f4b031bbd7f02b444ee1a3f2261295c526b201215938f9ec10b70905645494828c8487515fa9b2a64ff91098238308373c4498ac1407a46db112f1
|
7
|
+
data.tar.gz: ee4279d6451f918746e8644e454cdb8c79ad5c28a099588e154d5216c4eccd801463ecf5f1d80eef585750b17a51f7ff9712a494faa3665098137fe9c26c2901
|
data/README.md
CHANGED
@@ -74,12 +74,20 @@ end
|
|
74
74
|
#=> 'sample_key'
|
75
75
|
```
|
76
76
|
|
77
|
+
**safe_eval:**
|
78
|
+
`safe_eval` try to evalute or return it's nil.
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
'[1,2,3]'.safe_eval #=> [1,2,3]
|
82
|
+
'[#1,2,3]'.safe_eval #=> nil
|
83
|
+
```
|
84
|
+
|
77
85
|
**try_eval:**
|
78
86
|
`try_eval` try to evalute or return it's self.
|
79
87
|
|
80
88
|
```ruby
|
81
|
-
'[1,2,3]'.try_eval
|
82
|
-
'[
|
89
|
+
'[1,2,3]'.try_eval #=> [1,2,3]
|
90
|
+
'[#1,2,3]'.try_eval #=> '[#1,2,3]'
|
83
91
|
```
|
84
92
|
|
85
93
|
## Array
|
data/lib/active_object/kernel.rb
CHANGED
@@ -3,7 +3,16 @@
|
|
3
3
|
if ActiveObject.configuration.autoload_kernel
|
4
4
|
module Kernel
|
5
5
|
|
6
|
+
SANITIZE_EVAL_REGEX ||= /\[\d*,?\d*,?\d*\]/.freeze
|
7
|
+
|
6
8
|
# rubocop:disable Lint/RescueException, Security/Eval
|
9
|
+
def safe_eval
|
10
|
+
val = SANITIZE_EVAL_REGEX.match(self.to_s).to_s
|
11
|
+
return if val.nil?
|
12
|
+
|
13
|
+
eval(val)
|
14
|
+
end
|
15
|
+
|
7
16
|
def try_eval
|
8
17
|
eval(self)
|
9
18
|
rescue Exception
|