Sha256: cbd167d4d6c7d61cb1e250853b97075d4a1fda5f4e13427bbb605d6038744816

Contents?: true

Size: 865 Bytes

Versions: 51

Compression:

Stored size: 865 Bytes

Contents

module Dorsale
  module SmallData
    class Filter

      def initialize(jar)
        @jar = jar
      end

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

      def read
        if @jar['filters']
          begin
            JSON.parse @jar['filters']
          rescue JSON::ParserError
            {}
          end
        else
          {}
        end
      end

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

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

      def apply(query)
        read.each do |key, value|
          filter = strategy(key)

          if filter && filter.applies?(self.target)
            filter.set(key, value)
            query = filter.apply(query)
          end
        end

        return query
      end

    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
dorsale-2.3.5 app/models/dorsale/small_data/filter.rb
dorsale-2.3.4 app/models/dorsale/small_data/filter.rb
dorsale-2.3.3 app/models/dorsale/small_data/filter.rb
dorsale-2.3.2 app/models/dorsale/small_data/filter.rb
dorsale-2.3.1 app/models/dorsale/small_data/filter.rb
dorsale-2.3.0 app/models/dorsale/small_data/filter.rb
dorsale-2.2.16 app/models/dorsale/small_data/filter.rb
dorsale-2.2.15 app/models/dorsale/small_data/filter.rb
dorsale-2.2.14 app/models/dorsale/small_data/filter.rb
dorsale-2.2.13 app/models/dorsale/small_data/filter.rb
dorsale-2.2.12 app/models/dorsale/small_data/filter.rb
dorsale-2.2.11 app/models/dorsale/small_data/filter.rb
dorsale-2.2.10 app/models/dorsale/small_data/filter.rb
dorsale-2.2.9 app/models/dorsale/small_data/filter.rb
dorsale-2.2.8 app/models/dorsale/small_data/filter.rb
dorsale-2.2.6 app/models/dorsale/small_data/filter.rb
dorsale-2.2.5 app/models/dorsale/small_data/filter.rb
dorsale-2.2.4 app/models/dorsale/small_data/filter.rb
dorsale-2.2.3 app/models/dorsale/small_data/filter.rb
dorsale-2.2.2 app/models/dorsale/small_data/filter.rb