Sha256: d649664908ad9fbeebee8879871fffae58c117cb89a3f5cd05917c4435910faa

Contents?: true

Size: 1.1 KB

Versions: 36

Compression:

Stored size: 1.1 KB

Contents

module SearchFlip
  # The SearchFlip::Sortable mixin provides the chainable #custom method to
  # add arbitrary sections to the elasticsearch request

  module Customable
    def self.included(base)
      base.class_eval do
        attr_accessor :custom_value
      end
    end

    # Adds a fully custom field/section to the request, such that upcoming or
    # minor Elasticsearch features as well as other custom requirements can be
    # used without having yet specialized criteria methods.
    #
    # @note Use with caution, because using #custom will potentiall override
    #   other sections like +aggregations+, +query+, +sort+, etc if you use the
    #   the same section names.
    #
    # @example
    #   CommentIndex.custom(section: { argument: "value" }).request
    #   => {:section=>{:argument=>"value"},...}
    #
    # @param hash [Hash] The custom section that is added to the request
    #
    # @return [SearchFlip::Criteria] A newly created extended criteria

    def custom(hash)
      fresh.tap do |criteria|
        criteria.custom_value = (custom_value || {}).merge(hash)
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
search_flip-3.9.0 lib/search_flip/customable.rb
search_flip-4.0.0.beta16 lib/search_flip/customable.rb
search_flip-4.0.0.beta15 lib/search_flip/customable.rb
search_flip-4.0.0.beta14 lib/search_flip/customable.rb
search_flip-3.8.0 lib/search_flip/customable.rb
search_flip-4.0.0.beta13 lib/search_flip/customable.rb
search_flip-3.7.2 lib/search_flip/customable.rb
search_flip-4.0.0.beta12 lib/search_flip/customable.rb
search_flip-3.7.1 lib/search_flip/customable.rb
search_flip-4.0.0.beta11 lib/search_flip/customable.rb
search_flip-3.7.0 lib/search_flip/customable.rb
search_flip-4.0.0.beta10 lib/search_flip/customable.rb
search_flip-3.6.0 lib/search_flip/customable.rb
search_flip-3.5.0 lib/search_flip/customable.rb
search_flip-4.0.0.beta9 lib/search_flip/customable.rb
search_flip-4.0.0.beta8 lib/search_flip/customable.rb
search_flip-3.4.0 lib/search_flip/customable.rb
search_flip-3.3.0 lib/search_flip/customable.rb
search_flip-4.0.0.beta7 lib/search_flip/customable.rb
search_flip-4.0.0.beta6 lib/search_flip/customable.rb