Sha256: 6913664b48ce1d6b0184088a1a6b1f0290833d288fca872a8a734b770f3b56af

Contents?: true

Size: 1.53 KB

Versions: 7

Compression:

Stored size: 1.53 KB

Contents

module ElasticsearchRecord
  module Relation
    module ValueMethods
      # holds the query kind
      def kind_value
        @values.fetch(:kind, nil)
      end

      def kind_value=(value)
        # checks if records are already loaded - in this case we cannot mutate the query anymore
        assert_mutability!

        @values[:kind] = value.to_sym
      end

      def configure_value
        @values.fetch(:configure, {})
      end

      def configure_value=(value)
        assert_mutability!

        @values[:configure] = value
      end

      def query_clause
        @values.fetch(:query, ElasticsearchRecord::Relation::QueryClauseTree.empty)
      end

      def query_clause=(value)
        assert_mutability!

        @values[:query] = value
      end

      def aggs_clause
        @values.fetch(:aggs, ElasticsearchRecord::Relation::QueryClauseTree.empty)
      end

      def aggs_clause=(value)
        assert_mutability!

        @values[:aggs] = value
      end

      # overwrite the limit_value setter, to provide a special behaviour of auto-setting the +max_result_window+.
      def limit_value=(limit)
        if limit == '__max__' || (limit.nil? && delegate_query_nil_limit?)
          super(max_result_window)
        else
          super(limit)
        end
      end

      private

      # alternative method to avoid redefining the const +VALID_UNSCOPING_VALUES+
      def _valid_unscoping_values
        Set.new(ActiveRecord::Relation::VALID_UNSCOPING_VALUES.to_a + [:kind, :configure, :query, :aggs])
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
elasticsearch_record-1.8.0 lib/elasticsearch_record/relation/value_methods.rb
elasticsearch_record-1.7.2 lib/elasticsearch_record/relation/value_methods.rb
elasticsearch_record-1.7.1 lib/elasticsearch_record/relation/value_methods.rb
elasticsearch_record-1.7.0 lib/elasticsearch_record/relation/value_methods.rb
elasticsearch_record-1.6.0 lib/elasticsearch_record/relation/value_methods.rb
elasticsearch_record-1.5.3 lib/elasticsearch_record/relation/value_methods.rb
elasticsearch_record-1.5.2 lib/elasticsearch_record/relation/value_methods.rb