Class: Hyrax::SchemaLoader::AttributeDefinition Private
- Inherits:
-
Object
- Object
- Hyrax::SchemaLoader::AttributeDefinition
- Defined in:
- app/services/hyrax/schema_loader.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Direct Known Subclasses
Defined Under Namespace
Classes: Identity
Constant Summary collapse
- Coerce =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Cleans up the input before the type system sees it: drops the "no value provided" placeholder dry-types uses internally, then removes blanks. Wraps a bare Hash in a one-element array; using
Array(hash)would surprise-flatten it into [[:k, v], ...] pairs. Valkyrie's JSONValueMapper unwraps single-element arrays on read, so the type sees a hash here when there was originally one entry. lambda do |value| return [] if value.equal?(Dry::Types::Undefined) wrapped = value.is_a?(::Hash) ? [value] : Array(value) wrapped.reject { |v| v.equal?(Dry::Types::Undefined) }.select(&:present?) end
Instance Attribute Summary collapse
- #config ⇒ Object readonly private
- #name ⇒ Object readonly private
Instance Method Summary collapse
- #admin_only? ⇒ Boolean private
- #display_label ⇒ Object private
- #editor_only? ⇒ Boolean private
- #form_options ⇒ Hash{Symbol => Object} private
- #index_keys ⇒ Enumerable<Symbol> private
-
#initialize(name, config) ⇒ AttributeDefinition
constructor
private
A new instance of AttributeDefinition.
-
#multiple? ⇒ Boolean
private
Determine whether this attribute allows multiple values.
- #type ⇒ Dry::Types::Type private
- #view_options ⇒ Hash{Symbol => Object} private
Constructor Details
#initialize(name, config) ⇒ AttributeDefinition
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of AttributeDefinition.
65 66 67 68 |
# File 'app/services/hyrax/schema_loader.rb', line 65 def initialize(name, config) @config = config @name = (config['name'] || name).to_sym end |
Instance Attribute Details
#config ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 |
# File 'app/services/hyrax/schema_loader.rb', line 60 def config @config end |
#name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 |
# File 'app/services/hyrax/schema_loader.rb', line 60 def name @name end |
Instance Method Details
#admin_only? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
102 103 104 |
# File 'app/services/hyrax/schema_loader.rb', line 102 def admin_only? @admin_only ||= config.fetch('admin_only', false) || config['indexing']&.include?('admin_only') end |
#display_label ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
95 96 97 98 99 100 |
# File 'app/services/hyrax/schema_loader.rb', line 95 def display_label return @display_label if @display_label @display_label = config.fetch('display_label', {})&.with_indifferent_access || {} @display_label = { default: @display_label } if @display_label.is_a?(String) @display_label end |
#editor_only? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
106 107 108 |
# File 'app/services/hyrax/schema_loader.rb', line 106 def editor_only? @editor_only ||= config.fetch('editor_only', false) || config['indexing']&.include?('editor_only') end |
#form_options ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
72 73 74 |
# File 'app/services/hyrax/schema_loader.rb', line 72 def config.fetch('form', {})&.symbolize_keys || {} end |
#index_keys ⇒ Enumerable<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
78 79 80 |
# File 'app/services/hyrax/schema_loader.rb', line 78 def index_keys (config.fetch('indexing', nil) || config.fetch('index_keys', []))&.reject { |k| ['facetable', 'stored_searchable', 'admin_only', 'editor_only'].include?(k) }&.map(&:to_sym) || [] end |
#multiple? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determine whether this attribute allows multiple values.
131 132 133 134 135 136 137 138 |
# File 'app/services/hyrax/schema_loader.rb', line 131 def multiple? return config['multiple'] if config.key?('multiple') return true if config.key?('data_type') && config['data_type'] == 'array' return false unless (card = config['cardinality']) max = card['maximum'] max.nil? || max.to_i > 1 end |
#type ⇒ Dry::Types::Type
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
112 113 114 115 116 |
# File 'app/services/hyrax/schema_loader.rb', line 112 def type member_type = type_for(config['type']) wrapper_type = multiple? ? Valkyrie::Types::Array.constructor(&Coerce) : Identity wrapper_type.of(member_type) end |
#view_options ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
84 85 86 87 88 89 90 91 92 93 |
# File 'app/services/hyrax/schema_loader.rb', line 84 def # prefer display_label over view:label for labels, make available in the view @view_options = config.fetch('view', {})&.with_indifferent_access || {} Deprecation.warn('view: label is deprecated, use display_label instead') if @view_options[:label].present? @view_options.delete(:label) @view_options[:display_label] = display_label @view_options[:admin_only] = admin_only? @view_options[:editor_only] = editor_only? @view_options end |