Sha256: bf226bd0cc51c3978f16c72a6c4c20fd5af21c090fb3794716e1e9fbf130b2c6

Contents?: true

Size: 596 Bytes

Versions: 76

Compression:

Stored size: 596 Bytes

Contents

# frozen_string_literal: true

module Spotlight
  # A configurable solr filter for the exhibit
  class Filter < ActiveRecord::Base
    belongs_to :exhibit

    validates :field, :value, presence: true

    def to_hash
      return {} unless field

      { field => cast_value }
    end

    private

    def cast_value
      return value unless field

      if field.ends_with? Spotlight::Engine.config.solr_fields.boolean_suffix
        value_to_boolean(value)
      else
        value
      end
    end

    def value_to_boolean(v)
      ActiveModel::Type::Boolean.new.cast v
    end
  end
end

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
blacklight-spotlight-3.5.0.3 app/models/spotlight/filter.rb
blacklight-spotlight-3.6.0.beta6 app/models/spotlight/filter.rb
blacklight-spotlight-3.6.0.beta5 app/models/spotlight/filter.rb
blacklight-spotlight-3.6.0.beta4 app/models/spotlight/filter.rb
blacklight-spotlight-3.6.0.beta3 app/models/spotlight/filter.rb
blacklight-spotlight-3.6.0.beta1 app/models/spotlight/filter.rb
blacklight-spotlight-3.5.0.2 app/models/spotlight/filter.rb
blacklight-spotlight-3.5.0.1 app/models/spotlight/filter.rb
blacklight-spotlight-3.5.0 app/models/spotlight/filter.rb
blacklight-spotlight-3.4.4.1 app/models/spotlight/filter.rb
blacklight-spotlight-3.4.4 app/models/spotlight/filter.rb
blacklight-spotlight-3.4.3 app/models/spotlight/filter.rb
blacklight-spotlight-3.4.2.2 app/models/spotlight/filter.rb
blacklight-spotlight-3.4.2.1 app/models/spotlight/filter.rb
blacklight-spotlight-3.4.2 app/models/spotlight/filter.rb
blacklight-spotlight-3.4.1 app/models/spotlight/filter.rb
blacklight-spotlight-3.4.0 app/models/spotlight/filter.rb
blacklight-spotlight-3.3.0 app/models/spotlight/filter.rb
blacklight-spotlight-3.2.0 app/models/spotlight/filter.rb
blacklight-spotlight-3.1.0 app/models/spotlight/filter.rb