9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/infold/yaml_reader.rb', line 9
def generate_resource(resource_name, yaml, db_schema)
@db_schema = db_schema
field_group = FieldGroup.new(db_schema.table(resource_name))
resource = Resource.new(resource_name)
yaml = (yaml || {}).with_indifferent_access
model = yaml.dig('model') || {}
app = yaml.dig('app') || {}
assign_associations( field_group, model.dig(:association))
assign_active_storages( field_group, model.dig(:active_storage))
assign_validations( field_group, model.dig(:validate))
assign_enums( field_group, model.dig(:enum))
assign_enum_decorators( field_group, model.dig(:enum))
assign_decorators( field_group, model.dig(:decorator))
assign_search_conditions(field_group, app)
assign_list_fields( field_group, app)
assign_csv_fields( field_group, app)
assign_show_elements( field_group, app)
assign_form_elements( field_group, app)
resource.field_group = field_group
default_order = app.dig(:index, :list, :default_order)
if default_order&.dig(:field)
field = field_group.find_or_initialize_field(default_order.dig(:field))
resource.default_order = DefaultOrder.new(self, field, default_order.dig(:kind))
end
resource.app_title = app.dig(:title).presence ||
resource_name.pluralize.underscore.gsub('_', ' ').upcase
resource
end
|