Sha256: 556143795daaff6f2b482a1779da3ea18a2f05a3c589dfdc59662cca89ea09e6

Contents?: true

Size: 837 Bytes

Versions: 23

Compression:

Stored size: 837 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)
      if defined? ActiveModel::Type::Boolean
        ActiveModel::Type::Boolean.new.cast v
      elsif defined? ActiveRecord::Type::Boolean
        # Rails 4.2+
        ActiveRecord::Type::Boolean.new.type_cast_from_database v
      else
        ActiveRecord::ConnectionAdapters::Column.value_to_boolean v
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
blacklight-spotlight-0.34.1 app/models/spotlight/filter.rb
blacklight-spotlight-0.34.0 app/models/spotlight/filter.rb
blacklight-spotlight-0.33.3 app/models/spotlight/filter.rb
blacklight-spotlight-0.33.2 app/models/spotlight/filter.rb
blacklight-spotlight-0.33.1 app/models/spotlight/filter.rb
blacklight-spotlight-0.33.0 app/models/spotlight/filter.rb
blacklight-spotlight-0.32.0 app/models/spotlight/filter.rb
blacklight-spotlight-0.31.0 app/models/spotlight/filter.rb
blacklight-spotlight-0.30.0 app/models/spotlight/filter.rb
blacklight-spotlight-0.29.1 app/models/spotlight/filter.rb
blacklight-spotlight-0.29.0 app/models/spotlight/filter.rb
blacklight-spotlight-0.28.3 app/models/spotlight/filter.rb
blacklight-spotlight-0.28.2 app/models/spotlight/filter.rb
blacklight-spotlight-0.28.1 app/models/spotlight/filter.rb
blacklight-spotlight-0.28.0 app/models/spotlight/filter.rb
blacklight-spotlight-0.27.0 app/models/spotlight/filter.rb
blacklight-spotlight-0.26.1 app/models/spotlight/filter.rb
blacklight-spotlight-0.26.0 app/models/spotlight/filter.rb
blacklight-spotlight-0.25.0 app/models/spotlight/filter.rb
blacklight-spotlight-0.24.0 app/models/spotlight/filter.rb