forest_admin_datasource_active_record 1.0.0.pre.beta.26 → 1.0.0.pre.beta.28
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06346efeeba850f484fa80d25cb20f8b56ef3b9456642d79273a0e254f644a23
|
4
|
+
data.tar.gz: 9442cf45428756e117e6c77a798116b50831d939ab5d563a6a2b3947ff4022b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5701dd523335a31b83cd67fd608dd3566793375343785f45bfefae2f3260009b6475b669fb13b29c8dcb5edd431ed652fb7d3a60d1fae51e3534dcdf6b543899
|
7
|
+
data.tar.gz: 84d911c1d21163388430aa46eb06a7a3d7f67aa61afb5e7fab839d369711ff53ffadbaa7fbf1a498e4ec81ffe08744bdaeeaf5ebbdc44fb9965298e88979ac20
|
@@ -18,7 +18,7 @@ module ForestAdminDatasourceActiveRecord
|
|
18
18
|
def list(_caller, filter, projection)
|
19
19
|
query = Utils::Query.new(self, projection, filter).build
|
20
20
|
|
21
|
-
query.all
|
21
|
+
query.all.map { |record| Utils::ActiveRecordSerializer.new(record).to_hash }
|
22
22
|
end
|
23
23
|
|
24
24
|
def aggregate(_caller, filter, aggregation, limit = nil)
|
@@ -26,7 +26,7 @@ module ForestAdminDatasourceActiveRecord
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def create(_caller, data)
|
29
|
-
@model.create(data)
|
29
|
+
Utils::ActiveRecordSerializer.new(@model.create(data)).to_hash
|
30
30
|
end
|
31
31
|
|
32
32
|
def update(_caller, filter, data)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ForestAdminDatasourceActiveRecord
|
2
|
+
module Utils
|
3
|
+
ActiveRecordSerializer = Struct.new(:object) do
|
4
|
+
def to_hash
|
5
|
+
hash_object(object)
|
6
|
+
end
|
7
|
+
|
8
|
+
def hash_object(object, with_associations: true)
|
9
|
+
hash = {}
|
10
|
+
|
11
|
+
return {} if object.nil?
|
12
|
+
|
13
|
+
hash.merge! object.attributes
|
14
|
+
|
15
|
+
if with_associations
|
16
|
+
each_association_collection(object) do |association_name, item|
|
17
|
+
hash[association_name] = hash_object(item, with_associations: false)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
hash
|
22
|
+
end
|
23
|
+
|
24
|
+
def each_association_collection(object)
|
25
|
+
one_associations = %i[has_one belongs_to]
|
26
|
+
object.class.reflect_on_all_associations.filter { |a| one_associations.include?(a.macro) }
|
27
|
+
.each { |association| yield(association.name.to_s, object.send(association.name.to_s)) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forest_admin_datasource_active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.beta.
|
4
|
+
version: 1.0.0.pre.beta.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-01-
|
12
|
+
date: 2024-01-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- lib/forest_admin_datasource_active_record/parser/column.rb
|
74
74
|
- lib/forest_admin_datasource_active_record/parser/relation.rb
|
75
75
|
- lib/forest_admin_datasource_active_record/parser/validation.rb
|
76
|
+
- lib/forest_admin_datasource_active_record/utils/active_record_serializer.rb
|
76
77
|
- lib/forest_admin_datasource_active_record/utils/query.rb
|
77
78
|
- lib/forest_admin_datasource_active_record/utils/query_aggregate.rb
|
78
79
|
- lib/forest_admin_datasource_active_record/version.rb
|