Class: ForestAdminAgent::Utils::Schema::GeneratorCollection
- Inherits:
-
Object
- Object
- ForestAdminAgent::Utils::Schema::GeneratorCollection
- Includes:
- ForestAdminDatasourceToolkit::Utils
- Defined in:
- lib/forest_admin_agent/utils/schema/generator_collection.rb
Class Method Summary collapse
- .build_actions(collection) ⇒ Object
- .build_fields(collection) ⇒ Object
- .build_schema(collection) ⇒ Object
- .build_segments(collection) ⇒ Object
Class Method Details
.build_actions(collection) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/forest_admin_agent/utils/schema/generator_collection.rb', line 33 def self.build_actions(collection) if collection.schema[:actions] collection.schema[:actions].keys.sort.map { |name| GeneratorAction.build_schema(collection, name) } else {} end end |
.build_fields(collection) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/forest_admin_agent/utils/schema/generator_collection.rb', line 23 def self.build_fields(collection) fields = collection.schema[:fields].select do |name, _field| !ForestAdminDatasourceToolkit::Utils::Schema.foreign_key?(collection, name) || ForestAdminDatasourceToolkit::Utils::Schema.primary_key?(collection, name) end fields.map { |name, _field| GeneratorField.build_schema(collection, name) } .sort_by { |v| v[:field] } end |
.build_schema(collection) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/forest_admin_agent/utils/schema/generator_collection.rb', line 7 def self.build_schema(collection) { actions: build_actions(collection), fields: build_fields(collection), icon: nil, integration: nil, isReadOnly: collection.schema[:fields].all? { |_k, field| field.type != 'Column' || field.is_read_only }, isSearchable: collection.schema[:searchable], isVirtual: false, name: collection.name, onlyForRelationships: false, paginationType: 'page', segments: build_segments(collection) } end |
.build_segments(collection) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/forest_admin_agent/utils/schema/generator_collection.rb', line 41 def self.build_segments(collection) if collection.schema[:segments] collection.schema[:segments].sort.map { |name| { id: "#{collection.name}.#{name}", name: name } } else [] end end |