forest_admin_datasource_toolkit 1.0.0.pre.beta.39 → 1.0.0.pre.beta.41

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: fcb52ad66ef9bb7fb851f4165cf3f3e9e9a7ba341c78d8e5c15a6618018ff901
4
- data.tar.gz: 5c13c7155c58188b3f54302a093fb2e03ffe0b7281732845b74cf45c6d5dc967
3
+ metadata.gz: 1035a539d283d780ed5f275c2201cd90151f5fda9b411c962f04bce55f8d5635
4
+ data.tar.gz: 605fc837c85f9adb4599902dc34f2a2c9c8cbe490415ecea5bd6a088cdeec794
5
5
  SHA512:
6
- metadata.gz: 3aa5b2c0a11a04485e9c317d1ab636208305cd27fbf9c65ac56846a5fd606a35c725c6d645110a3d94b797229a5a3ff20e1bdf9a3172dc96fafaa93bcc292796
7
- data.tar.gz: a77bd6a941a15c0b203733642d0cb7dd3a4a763680d98ccd3fea61cca7e36ed841222ab3dd7244f06ed8c52b42b8fd4aeff808b8ea556df383958efcc8cdeff5
6
+ metadata.gz: 6030038abe0c9539e36cac0552935e23783f4edd5293063c88cb07a41b829636b0d29cade972264c471318a61527bcbfd093bcdeb5cb3580adc6d5bae2a1ebc5
7
+ data.tar.gz: 967c956a40ebb8d304e989eb3f6c66b95c4a22f9fb023db2a84e5e7c02c620d35a477663336425a0f9996d18f656d95da38e824b86bb4b5af9a5f9f18ccd0b13
@@ -3,7 +3,6 @@ module ForestAdminDatasourceToolkit
3
3
  attr_accessor :segments
4
4
 
5
5
  attr_reader :actions,
6
- :charts,
7
6
  :datasource,
8
7
  :name,
9
8
  :schema,
@@ -17,11 +16,11 @@ module ForestAdminDatasourceToolkit
17
16
  @schema = {
18
17
  fields: {},
19
18
  countable: false,
20
- searchable: false
19
+ searchable: false,
20
+ charts: []
21
21
  }
22
22
  @actions = {}
23
23
  @segments = {}
24
- @charts = {}
25
24
  end
26
25
 
27
26
  def enable_count
@@ -57,5 +56,9 @@ module ForestAdminDatasourceToolkit
57
56
 
58
57
  @actions[name] = action
59
58
  end
59
+
60
+ def render_chart(_caller, name, _record_id)
61
+ raise Exceptions::ForestException, "Chart #{name} is not implemented."
62
+ end
60
63
  end
61
64
  end
@@ -6,10 +6,6 @@ module ForestAdminDatasourceToolkit
6
6
  raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
7
7
  end
8
8
 
9
- def charts
10
- raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
11
- end
12
-
13
9
  def get_collection(name)
14
10
  raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
15
11
  end
@@ -1,10 +1,10 @@
1
1
  module ForestAdminDatasourceToolkit
2
2
  class Datasource < Components::Contracts::DatasourceContract
3
- attr_reader :collections, :charts
3
+ attr_reader :collections, :schema
4
4
 
5
5
  def initialize
6
6
  super
7
- @charts = {}
7
+ @schema = { charts: [] }
8
8
  @collections = {}
9
9
  end
10
10
 
@@ -7,6 +7,10 @@ module ForestAdminDatasourceToolkit
7
7
  @decorators = {}
8
8
  end
9
9
 
10
+ def schema
11
+ @child_datasource.schema
12
+ end
13
+
10
14
  def collections
11
15
  @child_datasource.collections.transform_values { |c| get_collection(c.name) }
12
16
  end
@@ -16,8 +16,10 @@ module ForestAdminDatasourceToolkit
16
16
  "Unexpected field type: '#{collection.name}.#{field}' (found '#{schema.type}' expected 'Column')"
17
17
  end
18
18
 
19
- values&.each do |value|
20
- validate_value(field, schema, value)
19
+ if values.is_a?(Array)
20
+ values.each do |value|
21
+ validate_value(field, schema, value)
22
+ end
21
23
  end
22
24
  else
23
25
  prefix = field[0, dot_index]
@@ -0,0 +1,27 @@
1
+ module ForestAdminDatasourceToolkit
2
+ module Validations
3
+ class RecordValidator
4
+ include ForestAdminDatasourceToolkit::Exceptions
5
+
6
+ def self.validate(collection, record_data)
7
+ raise ForestException, 'The record data is empty' if !record_data || record_data.empty?
8
+
9
+ record_data.each_key do |key|
10
+ schema = collection.schema[:fields][key]
11
+
12
+ if !schema
13
+ raise ForestException, "Unknown field #{key}"
14
+ elsif schema.type == 'Column'
15
+ FieldValidator.validate(collection, key, record_data[key])
16
+ elsif schema.type == 'OneToOne' || schema.type == 'ManyToOne'
17
+ sub_record = record_data[key]
18
+ association = collection.datasource.get_collection(schema.foreign_collection)
19
+ RecordValidator.validate(association, sub_record)
20
+ else
21
+ raise ForestException, "Unexpected schema type '#{schema.type}' while traversing record"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module ForestAdminDatasourceToolkit
2
- VERSION = "1.0.0-beta.39"
2
+ VERSION = "1.0.0-beta.41"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_admin_datasource_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.beta.39
4
+ version: 1.0.0.pre.beta.41
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-03-22 00:00:00.000000000 Z
12
+ date: 2024-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -106,6 +106,7 @@ files:
106
106
  - lib/forest_admin_datasource_toolkit/validations/condition_tree_validator.rb
107
107
  - lib/forest_admin_datasource_toolkit/validations/field_validator.rb
108
108
  - lib/forest_admin_datasource_toolkit/validations/projection_validator.rb
109
+ - lib/forest_admin_datasource_toolkit/validations/record_validator.rb
109
110
  - lib/forest_admin_datasource_toolkit/validations/rules.rb
110
111
  - lib/forest_admin_datasource_toolkit/validations/sort_validator.rb
111
112
  - lib/forest_admin_datasource_toolkit/validations/type_getter.rb