Module: AdminSuite::Mcp::Serializer
- Defined in:
- lib/admin_suite/mcp/serializer.rb
Overview
Serializes only fields declared by the resource DSL. This is the MCP surface's data-exposure boundary.
Class Method Summary collapse
- .associations_payload(record, config, max_rows:) ⇒ Object
- .dump(payload) ⇒ Object
- .index_row(record, config) ⇒ Object
- .show_payload(record, config) ⇒ Object
Class Method Details
.associations_payload(record, config, max_rows:) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/admin_suite/mcp/serializer.rb', line 25 def self.associations_payload(record, config, max_rows:) sections = config.show_config&..to_a + config.show_config&.main_sections.to_a sections.each_with_object({}) do |section, payload| next if section.association.blank? || section.columns.blank? payload[section.name] = association_panel(record, section, max_rows) end end |
.dump(payload) ⇒ Object
34 35 36 |
# File 'lib/admin_suite/mcp/serializer.rb', line 34 def self.dump(payload) JSON.pretty_generate(primitive(payload)) end |
.index_row(record, config) ⇒ Object
8 9 10 11 12 |
# File 'lib/admin_suite/mcp/serializer.rb', line 8 def self.index_row(record, config) config.index_config.columns_list.each_with_object({}) do |column, row| row[column.name] = primitive(resolve_column(record, column)) end end |
.show_payload(record, config) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/admin_suite/mcp/serializer.rb', line 14 def self.show_payload(record, config) sections = config.show_config&..to_a + config.show_config&.main_sections.to_a sections.each_with_object({}) do |section, payload| Array(section.fields).each do |field| payload[field] = primitive(value_for(record, field)) end end end |