Class: Spotlight::UploadFieldConfig
- Inherits:
 - 
      Object
      
        
- Object
 - Spotlight::UploadFieldConfig
 
 
- 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
- 
  
    
      #blacklight_options  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute blacklight_options.
 - 
  
    
      #field_name  ⇒ Object 
    
    
      (also: #solr_field)
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute field_name.
 - 
  
    
      #form_field_type  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute form_field_type.
 
Instance Method Summary collapse
- #data_to_solr(value) ⇒ Object
 - 
  
    
      #initialize(field_name:, blacklight_options: {}, form_field_type: :text_field, label: nil, solr_fields: nil)  ⇒ UploadFieldConfig 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of UploadFieldConfig.
 - 
  
    
      #label  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Allows a proc to be set as the label.
 - 
  
    
      #solr_fields  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
providing backwards compatibility with the old way of configuring upload fields.
 
Constructor Details
#initialize(field_name:, blacklight_options: {}, 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(field_name:, blacklight_options: {}, form_field_type: :text_field, label: nil, solr_fields: nil) @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_options ⇒ Object (readonly)
Returns the value of attribute blacklight_options.
      10 11 12  | 
    
      # File 'lib/spotlight/upload_field_config.rb', line 10 def @blacklight_options end  | 
  
#field_name ⇒ Object (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_type ⇒ Object (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  | 
  
#label ⇒ Object
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_fields ⇒ Object
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  |