Sha256: 8657680f7b33e008c339c0f018f0c7775ca80992811e0bef78b744fac8b8a621

Contents?: true

Size: 565 Bytes

Versions: 27

Compression:

Stored size: 565 Bytes

Contents

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

27 entries across 27 versions & 1 rubygems

Version Path
blacklight-spotlight-2.4.1 app/models/spotlight/filter.rb
blacklight-spotlight-2.4.0 app/models/spotlight/filter.rb
blacklight-spotlight-2.3.3 app/models/spotlight/filter.rb
blacklight-spotlight-2.3.2 app/models/spotlight/filter.rb
blacklight-spotlight-2.3.1 app/models/spotlight/filter.rb
blacklight-spotlight-2.3.0 app/models/spotlight/filter.rb
blacklight-spotlight-2.2.1 app/models/spotlight/filter.rb
blacklight-spotlight-2.2.0 app/models/spotlight/filter.rb
blacklight-spotlight-2.1.0 app/models/spotlight/filter.rb
blacklight-spotlight-2.0.2 app/models/spotlight/filter.rb
blacklight-spotlight-2.0.1 app/models/spotlight/filter.rb
blacklight-spotlight-2.0.0 app/models/spotlight/filter.rb
blacklight-spotlight-2.0.0.rc6 app/models/spotlight/filter.rb
blacklight-spotlight-2.0.0.rc5 app/models/spotlight/filter.rb
blacklight-spotlight-2.0.0.rc4 app/models/spotlight/filter.rb
blacklight-spotlight-2.0.0.rc3 app/models/spotlight/filter.rb
blacklight-spotlight-2.0.0.rc2 app/models/spotlight/filter.rb
blacklight-spotlight-2.0.0.rc1 app/models/spotlight/filter.rb
blacklight-spotlight-1.5.1 app/models/spotlight/filter.rb
blacklight-spotlight-1.4.1 app/models/spotlight/filter.rb