jsonize 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jsonize/version.rb +1 -1
- data/lib/jsonize.rb +19 -9
- 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: bdb7d503cc06ab7caf4bad0cfb1f7162fab524a76d7cfc5d24c695f58231f5ae
|
4
|
+
data.tar.gz: 5d4ac6b92ab4f1893d7cd23609460e9f2009bd646f1df4f2878a5fa4db758465
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93ee3812b793b0dd34f88df23bc3438372d7cfb07d1ddefa72026bd9a064e37e4d5689bb13d46ae8eff5e62e90ee844f16179235d4806ec71519ff6dc87e89f1
|
7
|
+
data.tar.gz: 8830854c6b28efcdeae92aebef0b75138a6f85fc87be5016931374b7b3c2f32c2cec8a0aa133f6a14db1634d83ed5db7f2ab8be7baa40a1603000611e882809d
|
data/lib/jsonize/version.rb
CHANGED
data/lib/jsonize.rb
CHANGED
@@ -44,12 +44,13 @@ module Jsonize
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def generate_json propses,
|
47
|
+
def generate_json propses, options = {}
|
48
48
|
propses.reduce({}) do |r, (name, props)|
|
49
49
|
value =
|
50
|
-
if props["rule"]
|
51
|
-
|
52
|
-
elsif props["rule"].is_a?(String)
|
50
|
+
if props["rule"] == '_reflection'
|
51
|
+
send(name).as_json(options[name.to_sym] || {})
|
52
|
+
elsif props["rule"].is_a?(String) # NOTE required for sidekiq key
|
53
|
+
extenrals = options[:externals]
|
53
54
|
externals.fetch(props["rule"].to_sym) { |x| externals[props["rule"]] }
|
54
55
|
elsif props["real_name"] != name.to_s
|
55
56
|
read_attribute(props["real_name"]).as_json
|
@@ -70,7 +71,8 @@ module Jsonize
|
|
70
71
|
embed_attrs,
|
71
72
|
additional_attrs,
|
72
73
|
external_attrs(options),
|
73
|
-
options[:map] || {}
|
74
|
+
options[:map] || {},
|
75
|
+
_reflections
|
74
76
|
].reduce { |r, hash| r.merge(hash.map {|k,v| [k.to_sym, v] }.to_h) }
|
75
77
|
except = options.fetch(:except, [])
|
76
78
|
only = options.fetch(:only, self.attributes.keys.map(&:to_sym) | (options[:map] || {}).keys | embed_attrs.keys | external_attrs(options).keys)
|
@@ -81,19 +83,27 @@ module Jsonize
|
|
81
83
|
next nil if except.include?(name.to_sym) || (only & [ name.to_sym, name_in.to_sym ].uniq).blank?
|
82
84
|
|
83
85
|
rule = parse_rule(rule_in)
|
84
|
-
#binding.pry
|
85
86
|
[name, { "rule" => rule, "real_name" => name_in.to_s }]
|
86
87
|
end.compact.to_h
|
87
88
|
end
|
88
89
|
|
89
90
|
def parse_rule rule_in
|
90
|
-
|
91
|
+
case rule_in
|
92
|
+
when TrueClass, FalseClass, NilClass
|
93
|
+
true
|
94
|
+
when ActiveRecord::Reflection::AbstractReflection
|
95
|
+
'_reflection'
|
96
|
+
when Symbol, String
|
97
|
+
rule_in.to_s
|
98
|
+
else
|
99
|
+
true
|
100
|
+
end
|
91
101
|
end
|
92
102
|
|
93
103
|
def jsonize options = {}
|
94
104
|
attr_props = prepare_json(options)
|
95
105
|
redisize_json(attr_props) do
|
96
|
-
generate_json(attr_props, options
|
106
|
+
generate_json(attr_props, options)
|
97
107
|
end
|
98
108
|
end
|
99
109
|
|
@@ -104,7 +114,7 @@ module Jsonize
|
|
104
114
|
|
105
115
|
def as_json options = {}
|
106
116
|
attr_props = prepare_json(options)
|
107
|
-
generate_json(attr_props, options
|
117
|
+
generate_json(attr_props, options)
|
108
118
|
end
|
109
119
|
|
110
120
|
module Relation
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel «Malo» Skrylev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redisize
|