administrate-field-jsonb 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -0
- data/administrate-field-jsonb.gemspec +1 -1
- data/lib/administrate/field/jsonb.rb +9 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d4a9776ee5caf943947c684303277986d47df37cb27216d7ae1b4ad250e24bf
|
4
|
+
data.tar.gz: f35fd68170da0c3072b453c554327b26d0fa596a20afa9cd079fe3e6646bf893
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e5c81e3b1509fb8615efe31789430dbdf4d01b99c73fc2f19c25c6772b8f13a51eb7e3d1f985c05074e5b5601a29097bf6c70796403e900fb9f59828bb9f32a
|
7
|
+
data.tar.gz: 49a1e3751dfce8da3d4ccd6bb16ffad797824cbaf96f0d215b5d0c1c59d35b42ddb495ea53462d331a21699b7655c6552ce9577f46e37d7dc654d2ceeacab274
|
data/README.md
CHANGED
@@ -47,6 +47,28 @@ ATTRIBUTE_TYPES = {
|
|
47
47
|
}.freeze
|
48
48
|
```
|
49
49
|
|
50
|
+
It also supports Proc.
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
ATTRIBUTE_TYPES = {
|
54
|
+
# ...
|
55
|
+
details: Field::JSONB.with_options(
|
56
|
+
transform: [:transformation, Proc.new { |item| item.merge({ foo: 'bar' }) }]
|
57
|
+
)
|
58
|
+
}.freeze
|
59
|
+
```
|
60
|
+
|
61
|
+
And there is a built in `parse_json` option, it will call `JSON.parse(your_object)` on your object.
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
ATTRIBUTE_TYPES = {
|
65
|
+
# ...
|
66
|
+
details: Field::JSONB.with_options(
|
67
|
+
transform: [:parse_json, :some_other_stuff]
|
68
|
+
)
|
69
|
+
}.freeze
|
70
|
+
```
|
71
|
+
|
50
72
|
If you want to edit json displaying on `show` page, you can use `advanced_view` option (both JSON and arrays are supported).
|
51
73
|
|
52
74
|
```ruby
|
@@ -2,7 +2,7 @@ $LOAD_PATH.push File.expand_path('lib', __dir__)
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = 'administrate-field-jsonb'
|
5
|
-
gem.version = '0.4.
|
5
|
+
gem.version = '0.4.6'
|
6
6
|
gem.authors = ['Sergey Volkov', 'Codica']
|
7
7
|
gem.email = ['sergvolkov.codica@gmail.com']
|
8
8
|
gem.homepage = 'https://github.com/codica2/administrate-field-jsonb'
|
@@ -14,7 +14,15 @@ module Administrate
|
|
14
14
|
|
15
15
|
result = data
|
16
16
|
options[:transform].each do |method|
|
17
|
-
result =
|
17
|
+
result = if method == :parse_json
|
18
|
+
JSON.parse(result) rescue result
|
19
|
+
elsif result.is_a?(Array)
|
20
|
+
result.map(&method)
|
21
|
+
elsif method.is_a?(Proc)
|
22
|
+
method.call(result)
|
23
|
+
else
|
24
|
+
result.public_send(method)
|
25
|
+
end
|
18
26
|
end
|
19
27
|
result
|
20
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: administrate-field-jsonb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Volkov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-09-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: administrate
|