administrate-field-jsonb 0.4.5 → 0.4.7
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 +33 -0
- data/administrate-field-jsonb.gemspec +1 -1
- data/lib/administrate/field/jsonb.rb +10 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52209531e57fde3e665caf40eecc5d76c6e43b878f00b3a8881f4b74e1d57ab3
|
4
|
+
data.tar.gz: 8c9908a227df51cc20c04b05869564334b242a02c729c996faf6e0e828ed2424
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67893b05ca6c084eca1a5fe4790d91213db15797ccb3c406f8ebdf6439a976945328e7d9568c50f314a6688a65aafae4a207ae258d43c960ee03ffbbeeeb05a8
|
7
|
+
data.tar.gz: b8257459ee97d75c948dc363136db331b0a564c74a82e4f2ef3b138d3ab96d82c7149cd6b16888b8985250beb1507da34370d5ba8c74b5e59b38aeee01bf1732
|
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
|
@@ -80,6 +102,17 @@ ATTRIBUTE_TYPES = {
|
|
80
102
|
}.freeze
|
81
103
|
```
|
82
104
|
|
105
|
+
In some situations you may preffer not to nullify empty records. For example you store your JSONB in `not null` database column and always have at least an empty json object `{}`. In such situation you can use `nil_blank` option:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
ATTRIBUTE_TYPES = {
|
109
|
+
# ...
|
110
|
+
details: Field::JSONB.with_options(
|
111
|
+
nil_blank: false
|
112
|
+
)
|
113
|
+
}.freeze
|
114
|
+
```
|
115
|
+
|
83
116
|
## How it looks like
|
84
117
|
|
85
118
|
### Form
|
@@ -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.7'
|
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'
|
@@ -9,12 +9,20 @@ module Administrate
|
|
9
9
|
class JSONB < Administrate::Field::Base
|
10
10
|
|
11
11
|
def transform
|
12
|
-
return nil if data.blank?
|
12
|
+
return nil if data.blank? && (!options.key?(:nil_blank) || options[:nil_blank] == true)
|
13
13
|
return data unless options[:transform].present? && options[:transform].is_a?(Array)
|
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.7
|
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:
|
12
|
+
date: 2024-12-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: administrate
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
|
-
rubygems_version: 3.
|
110
|
+
rubygems_version: 3.5.16
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: JSONb field plugin for Administrate
|