forest_admin_datasource_active_record 1.0.0.pre.beta.27 → 1.0.0.pre.beta.29

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: e83bd3d0a6650600a831ed51ad4335fcd87695786ceb460a3d3ea68be333b227
4
- data.tar.gz: 1ef7d6c46b7d06874e60c73706307e34552eff4453cb6e3fea7093020a250e87
3
+ metadata.gz: 1235e10f48fafe924d21f9721901081fc4ca5de25959b4847e776efff4f4b61a
4
+ data.tar.gz: de106179b1f2d02874a45e7b36651c69666e5cc2a5fbce0e03c2600a2d0c60ab
5
5
  SHA512:
6
- metadata.gz: cd0954583ad0229fcc62dedcd9529aae5e9956da0e3c232c14940bedf3cd198dd8eb9a50372c16dd167bfc717eb1c9f6da01053e3d402f990521f49d25a47e29
7
- data.tar.gz: 2065641bc8b52125e56cccc296cc929329c1bb86aea013a1e6a6c90538a49e3092193d5fe3efad4f8df609142a462dc4dde4778dafd3774a99ba7029ccf79c17
6
+ metadata.gz: 8a34c4bbd41f6ef79ab5e83b8db1ad05fc692ddc3b5b47be9d3929b0a1b5e475267febe702a826bda47071cb3c9d0ac19cc251fabc1998237de38c94dac6ca9b
7
+ data.tar.gz: c52edb55dee99cc90518363df17c2c43e2d0ac09e9791929b741b73b54f8f03166fe99e09f5c4dfbed415f6e3eddf4201e60a59d51b9b02e04d42b619a3c4064
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ForestAdminDatasourceActiveRecord
2
- VERSION = "1.0.0-beta.27"
2
+ VERSION = "1.0.0-beta.29"
3
3
  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.27
4
+ version: 1.0.0.pre.beta.29
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-02 00:00:00.000000000 Z
12
+ date: 2024-01-24 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