Sha256: ccb3342b0d51fb74f905195e1794cd65faad336e806d08bf3127838923b2694a

Contents?: true

Size: 836 Bytes

Versions: 8

Compression:

Stored size: 836 Bytes

Contents

module FortyFacets
  class ScopeFilterDefinition < FilterDefinition
    class ScopeFilter < Filter
      def active?
        value == '1'
      end

      def build_scope
        return Proc.new { |base| base } unless active?
        Proc.new {  |base| base.send(definition.path.first) }
      end

      def remove
        new_params = search_instance.params || {}
        new_params.delete(definition.request_param)
        search_instance.class.new_unwrapped(new_params, search_instance.root)
      end

      def add
        new_params = search_instance.params || {}
        new_params[definition.request_param] = '1'
        search_instance.class.new_unwrapped(new_params, search_instance.root)
      end
    end

    def build_filter(search_instance, value)
      ScopeFilter.new(self, search_instance, value)
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
forty_facets-0.1.8 lib/forty_facets/filter/scope_filter_definition.rb
forty_facets-0.1.7 lib/forty_facets/filter/scope_filter_definition.rb
forty_facets-0.1.6 lib/forty_facets/filter/scope_filter_definition.rb
forty_facets-0.1.5 lib/forty_facets/filter/scope_filter_definition.rb
forty_facets-0.1.4 lib/forty_facets/filter/scope_filter_definition.rb
forty_facets-0.1.3 lib/forty_facets/filter/scope_filter_definition.rb
forty_facets-0.1.2 lib/forty_facets/filter/scope_filter_definition.rb
forty_facets-0.1.1 lib/forty_facets/filter/scope_filter_definition.rb