hanami-utils 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/lib/hanami/utils/json.rb +65 -1
- data/lib/hanami/utils/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: 147943727aa2419fd62308b8e482f1386f9790f8
|
4
|
+
data.tar.gz: 9a2db890e7da1a930a3adb14cffac52ff9affa33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 423676170211e4a123007b863e15393de3ca0e603113160a12d8e39143b08cd49a6d68a0089a20f100a83108a280ed466e1008cae601e0a2d99312e33b2487fa
|
7
|
+
data.tar.gz: 1c81a606b3bfbee8d3426f36db95662563861c693d5075928a2c12eae1f736dba65bafdf27b441f8963d4ef3f195d157dd615a4a27aae750dccaf830b079d0d9
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
# Hanami::Utils
|
2
2
|
Ruby core extentions and class utilities for Hanami
|
3
3
|
|
4
|
+
## v0.9.1 - 2016-11-18
|
5
|
+
### Added
|
6
|
+
- [Luca Guidi] Introduced `Utils::Json.parse` and `.generate`
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
- [Luca Guidi] Ensure `Utils::Json` parsing to not eval untrusted input
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
- [Luca Guidi] Deprecated `Utils::Json.load` in favor of `.parse`
|
13
|
+
- [Luca Guidi] Deprecated `Utils::Json.dump` in favor of `.generate`
|
14
|
+
|
4
15
|
## v0.9.0 - 2016-11-15
|
5
16
|
### Added
|
6
17
|
– [Luca Guidi] Introduced `Utils.require!` to recursively require Ruby files with an order that is consistent across platforms
|
data/lib/hanami/utils/json.rb
CHANGED
@@ -4,6 +4,8 @@ rescue LoadError
|
|
4
4
|
require 'json'
|
5
5
|
end
|
6
6
|
|
7
|
+
require 'hanami/utils/deprecation'
|
8
|
+
|
7
9
|
module Hanami
|
8
10
|
module Utils
|
9
11
|
# JSON wrapper
|
@@ -13,9 +15,41 @@ module Hanami
|
|
13
15
|
#
|
14
16
|
# @since 0.8.0
|
15
17
|
module Json
|
18
|
+
# MultiJson adapter
|
19
|
+
#
|
20
|
+
# @since 0.9.1
|
21
|
+
# @api private
|
22
|
+
class MultiJsonAdapter
|
23
|
+
# @since 0.9.1
|
24
|
+
# @api private
|
25
|
+
def parse(payload)
|
26
|
+
MultiJson.load(payload)
|
27
|
+
end
|
28
|
+
|
29
|
+
# FIXME: remove this alias, when Hanami::Utils::Json.load will be removed
|
30
|
+
#
|
31
|
+
# @since 0.9.1
|
32
|
+
# @api private
|
33
|
+
alias load parse
|
34
|
+
|
35
|
+
# FIXME: remove this method, when Hanami::Utils::Json.dump will be removed
|
36
|
+
#
|
37
|
+
# @since 0.9.1
|
38
|
+
# @api private
|
39
|
+
def dump(object)
|
40
|
+
generate(object)
|
41
|
+
end
|
42
|
+
|
43
|
+
# @since 0.9.1
|
44
|
+
# @api private
|
45
|
+
def generate(object)
|
46
|
+
MultiJson.dump(object)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
16
50
|
# rubocop:disable Style/ClassVars
|
17
51
|
if defined?(MultiJson)
|
18
|
-
@@engine =
|
52
|
+
@@engine = MultiJsonAdapter.new
|
19
53
|
ParserError = MultiJson::ParseError
|
20
54
|
else
|
21
55
|
@@engine = ::JSON
|
@@ -32,10 +66,26 @@ module Hanami
|
|
32
66
|
# @raise [Hanami::Utils::Json::ParserError] if the paylod is invalid
|
33
67
|
#
|
34
68
|
# @since 0.8.0
|
69
|
+
#
|
70
|
+
# @deprecated Use {.parse} instead
|
35
71
|
def self.load(payload)
|
72
|
+
Hanami::Utils::Deprecation.new("`Hanami::Utils::Json.load' is deprecated, please use `Hanami::Utils::Json.parse'")
|
36
73
|
@@engine.load(payload)
|
37
74
|
end
|
38
75
|
|
76
|
+
# Parse the given JSON paylod
|
77
|
+
#
|
78
|
+
# @param payload [String] a JSON payload
|
79
|
+
#
|
80
|
+
# @return [Object] the result of the loading process
|
81
|
+
#
|
82
|
+
# @raise [Hanami::Utils::Json::ParserError] if the paylod is invalid
|
83
|
+
#
|
84
|
+
# @since 0.9.1
|
85
|
+
def self.parse(payload)
|
86
|
+
@@engine.parse(payload)
|
87
|
+
end
|
88
|
+
|
39
89
|
# Dump the given object into a JSON payload
|
40
90
|
#
|
41
91
|
# @param object [Object] any object
|
@@ -43,9 +93,23 @@ module Hanami
|
|
43
93
|
# @return [String] the result of the dumping process
|
44
94
|
#
|
45
95
|
# @since 0.8.0
|
96
|
+
#
|
97
|
+
# @deprecated Use {.generate} instead
|
46
98
|
def self.dump(object)
|
99
|
+
Hanami::Utils::Deprecation.new("`Hanami::Utils::Json.dump' is deprecated, please use `Hanami::Utils::Json.generate'")
|
47
100
|
@@engine.dump(object)
|
48
101
|
end
|
102
|
+
|
103
|
+
# Generate a JSON document from the given object
|
104
|
+
#
|
105
|
+
# @param object [Object] any object
|
106
|
+
#
|
107
|
+
# @return [String] the result of the dumping process
|
108
|
+
#
|
109
|
+
# @since 0.9.1
|
110
|
+
def self.generate(object)
|
111
|
+
@@engine.generate(object)
|
112
|
+
end
|
49
113
|
end
|
50
114
|
end
|
51
115
|
end
|
data/lib/hanami/utils/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanami-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-11-
|
13
|
+
date: 2016-11-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
version: '0'
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.6.
|
99
|
+
rubygems_version: 2.6.8
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: Ruby core extentions and Hanami utilities
|