Module: ActionSchema::Controller
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/action_schema/controller.rb
Instance Method Summary collapse
- #resolve_schema(schema_name) ⇒ Object
- #schema_context ⇒ Object
- #schema_for(record_or_collection, schema_name = :default, context: {}, &block) ⇒ Object
Instance Method Details
#resolve_schema(schema_name) ⇒ Object
41 42 43 44 |
# File 'lib/action_schema/controller.rb', line 41 def resolve_schema(schema_name) self.class.action_schemas[schema_name] || raise(ArgumentError, "Schema `#{schema_name}` not defined") end |
#schema_context ⇒ Object
20 21 22 |
# File 'lib/action_schema/controller.rb', line 20 def schema_context resolve_schema_context(self.class.default_schema_context) end |
#schema_for(record_or_collection, schema_name = :default, context: {}, &block) ⇒ Object
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 |