Class: Hyrax::SchemaLoader::AttributeDefinition Private

Inherits:
Object
  • Object
show all
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.

Defined Under Namespace

Classes: Identity

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • name (#to_sym)
  • config (Hash<String, Object>)


65
66
67
68
# File 'app/services/hyrax/schema_loader.rb', line 65

def initialize(name, config)
  @config = config
  @name   = name.to_sym
end

Instance Attribute Details

#configObject (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

#nameObject (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.

Returns:

  • (Boolean)


101
102
103
# File 'app/services/hyrax/schema_loader.rb', line 101

def admin_only?
  @admin_only ||= config.fetch('admin_only', false) || config['indexing']&.include?('admin_only')
end

#display_labelObject

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.



94
95
96
97
98
99
# File 'app/services/hyrax/schema_loader.rb', line 94

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

#form_optionsHash{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.

Returns:

  • (Hash{Symbol => Object})


72
73
74
# File 'app/services/hyrax/schema_loader.rb', line 72

def form_options
  config.fetch('form', {})&.symbolize_keys || {}
end

#index_keysEnumerable<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.

Returns:

  • (Enumerable<Symbol>)


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'].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.

Returns:

  • (Boolean)


118
119
120
121
122
123
124
125
# File 'app/services/hyrax/schema_loader.rb', line 118

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

#typeDry::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.

Returns:

  • (Dry::Types::Type)


107
108
109
110
111
112
113
114
115
# File 'app/services/hyrax/schema_loader.rb', line 107

def type
  collection_type = if multiple?
                      Valkyrie::Types::Array.constructor { |v| Array(v).select(&:present?) }
                    else
                      Identity
                    end

  collection_type.of(type_for(config['type']))
end

#view_optionsHash{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.

Returns:

  • (Hash{Symbol => Object})


84
85
86
87
88
89
90
91
92
# File 'app/services/hyrax/schema_loader.rb', line 84

def view_options
  # prefer display_label over view:label for labels, make available in the view
  @view_options = config.fetch('view', {})&.with_indifferent_access || {}
  Deprecation.warn(self, '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
end