Class: Spotlight::UploadFieldConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/spotlight/upload_field_config.rb

Overview

A class to model the configuration required to build the Document Upload form. This configuration is also used in other places around the application (e.g. Metadata Field Config) See Spotlight::Engine.config.upload_fields for where this is consumed We should look into changing this to a standard blacklight field config in Blacklight 7

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blacklight_options: {}, field_name:, form_field_type: :text_field, label: nil, solr_fields: nil) ⇒ UploadFieldConfig

Returns a new instance of UploadFieldConfig.



12
13
14
15
16
17
18
# File 'lib/spotlight/upload_field_config.rb', line 12

def initialize(blacklight_options: {}, field_name:, form_field_type: :text_field, label: nil, solr_fields: nil)
  @blacklight_options = blacklight_options
  @field_name = field_name
  @form_field_type = form_field_type
  @solr_fields = solr_fields
  @label = label || field_name
end

Instance Attribute Details

#blacklight_optionsObject (readonly)

Returns the value of attribute blacklight_options.



10
11
12
# File 'lib/spotlight/upload_field_config.rb', line 10

def blacklight_options
  @blacklight_options
end

#field_nameObject (readonly) Also known as: solr_field

Returns the value of attribute field_name.



10
11
12
# File 'lib/spotlight/upload_field_config.rb', line 10

def field_name
  @field_name
end

#form_field_typeObject (readonly)

Returns the value of attribute form_field_type.



10
11
12
# File 'lib/spotlight/upload_field_config.rb', line 10

def form_field_type
  @form_field_type
end

Instance Method Details

#data_to_solr(value) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/spotlight/upload_field_config.rb', line 35

def data_to_solr(value)
  solr_fields.each_with_object({}) do |solr_field, solr_hash|
    if solr_field.is_a? Hash
      solr_field.each do |name, lambda|
        solr_hash[name] = lambda.call(value)
      end
    else
      solr_hash[solr_field] = value
    end
  end
end

#labelObject

Allows a proc to be set as the label



21
22
23
24
25
# File 'lib/spotlight/upload_field_config.rb', line 21

def label
  return @label.call if @label.is_a?(Proc)

  @label
end

#solr_fieldsObject

providing backwards compatibility with the old way of configuring upload fields



31
32
33
# File 'lib/spotlight/upload_field_config.rb', line 31

def solr_fields
  @solr_fields || Array(solr_field || field_name)
end