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_or_proc = :default, context: {}, &block) ⇒ Object
Instance Method Details
#resolve_schema(schema_name) ⇒ Object
43 44 45 46 |
# File 'lib/action_schema/controller.rb', line 43 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_or_proc = :default, context: {}, &block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/action_schema/controller.rb', line 24 def schema_for(record_or_collection, schema_name_or_proc = :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_or_proc.is_a?(Proc) Class.new(ActionSchema.configuration.base_class, &Dalambda[schema_name_or_proc]) elsif schema_name_or_proc.is_a?(Class) schema_name_or_proc else self.class.action_schemas[schema_name_or_proc] end raise ArgumentError, "Schema `#{schema_name_or_proc}` not defined" unless schema_definition schema_definition.new(record_or_collection, context: combined_schema_context, controller: self).render end |