Sha256: 62f3d631883179b7b2dd4fe0320a33f5bf744e082f8206d4b3bd5e597c4e1543
Contents?: true
Size: 1.21 KB
Versions: 14
Compression:
Stored size: 1.21 KB
Contents
# frozen_string_literal: true module Hyrax ## # @api public # # @param [Symbol] schema_name # # @since 3.0.0 def self.FormFields(schema_name, **options) Hyrax::FormFields.new(schema_name, **options) end ## # @api private # # @see .FormFields class FormFields < Module attr_reader :name ## # @api private # # @param [Symbol] schema_name # @param [#form_definitions_for] definition_loader # # @note use Hyrax::FormFields(:my_schema) instead def initialize(schema_name, definition_loader: SimpleSchemaLoader.new) @name = schema_name @definition_loader = definition_loader end ## # @return [Hash{Symbol => Hash{Symbol => Object}}] def form_field_definitions @definition_loader.form_definitions_for(schema: name) end ## # @return [String] def inspect "#{self.class}(#{@name})" end private def included(descendant) super form_field_definitions.each do |field_name, options| descendant.property field_name.to_sym, options.merge(display: true, default: []) descendant.validates field_name.to_sym, presence: true if options.fetch(:required, false) end end end end
Version data entries
14 entries across 14 versions & 1 rubygems