24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/action_schema/controller.rb', line 24
def schema_for(record_or_collection, schema_name = :default, context: {}, &block)
combined_schema_context = schema_context.merge(resolve_schema_context(context))
schema_definition =
if block_given?
Class.new(ActionSchema.configuration.base_class, &block)
elsif schema_name.is_a?(Class)
schema_name
else
self.class.action_schemas[schema_name]
end
raise ArgumentError, "Schema `#{schema_name}` not defined" unless schema_definition
schema_definition.new(record_or_collection, context: combined_schema_context, controller: self).render
end
|