Sha256: cc32fe07e554ac0581ee504bad2cc89778e9812fb96ac5ebbfe8fee9c2d99288

Contents?: true

Size: 751 Bytes

Versions: 7

Compression:

Stored size: 751 Bytes

Contents

class Dorsale::SmallData::Filter
  def initialize(jar)
    @jar = jar
  end

  def store(filters)
    @jar["filters"] = filters.to_json
  end

  def read
    JSON.parse @jar["filters"].to_s
  rescue JSON::ParserError
    {}
  end

  def get(key)
    read[key.to_s]
  end

  def set(key, value)
    array           = read
    array[key.to_s] = value
    store(array)
  end

  def strategies
    self.class::STRATEGIES
  end

  def apply(query)
    strategies.each do |key, strategy|
      value = get(key)

      next if value.blank?

      query = strategy.apply(query, value)
    end

    return query
  end

  def method_missing(method, *args)
    key = method.to_s

    if strategies.key?(key)
      get(key)
    else
      super
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dorsale-3.1.6 app/filters/dorsale/small_data/filter.rb
dorsale-3.1.5 app/filters/dorsale/small_data/filter.rb
dorsale-3.1.4 app/models/dorsale/small_data/filter.rb
dorsale-3.1.3 app/models/dorsale/small_data/filter.rb
dorsale-3.1.2 app/models/dorsale/small_data/filter.rb
dorsale-3.1.1 app/models/dorsale/small_data/filter.rb
dorsale-3.1.0 app/models/dorsale/small_data/filter.rb