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 +4 -4
- data/lib/forest_admin_datasource_toolkit/collection.rb +6 -3
- data/lib/forest_admin_datasource_toolkit/components/contracts/datasource_contract.rb +0 -4
- data/lib/forest_admin_datasource_toolkit/datasource.rb +2 -2
- data/lib/forest_admin_datasource_toolkit/decorators/datasource_decorator.rb +4 -0
- data/lib/forest_admin_datasource_toolkit/validations/field_validator.rb +4 -2
- data/lib/forest_admin_datasource_toolkit/validations/record_validator.rb +27 -0
- data/lib/forest_admin_datasource_toolkit/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1035a539d283d780ed5f275c2201cd90151f5fda9b411c962f04bce55f8d5635
|
4
|
+
data.tar.gz: 605fc837c85f9adb4599902dc34f2a2c9c8cbe490415ecea5bd6a088cdeec794
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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, :
|
3
|
+
attr_reader :collections, :schema
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
super
|
7
|
-
@
|
7
|
+
@schema = { charts: [] }
|
8
8
|
@collections = {}
|
9
9
|
end
|
10
10
|
|
@@ -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
|
20
|
-
|
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
|
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.
|
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-
|
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
|