lib/tire/model/search.rb
# The default JSON serialization of the model, based on its `#to_hash` representation.
#
# If you don't define any mapping, the model is serialized as-is.
#
# If you do define the mapping for _Elasticsearch_, only attributes
# declared in the mapping are serialized.
#
# For properties declared with the `:as` option, the passed String or Proc
# is evaluated in the instance context. Other objects are indexed "as is".
#
The default JSON serialization of the model, based on its `#to_hash` representation.
If you don't define any mapping, the model is serialized as-is.

If you do define the mapping for _Elasticsearch_, only attributes
declared in the mapping are serialized.

For properties declared with the `:as` option, the passed String or Proc
is evaluated in the instance context. Other objects are indexed "as is".
The default JSON serialization of the model based on its ` #to_hash ` representation . If you don ' t define any mapping the model is serialized as - is . If you do define the mapping for _Elasticsearch_ only attributes declared in the mapping are serialized . For properties declared with the ` : as ` option the passed String or Proc is evaluated in the instance context . Other objects are indexed " as is " .
def to_indexed_json
          if instance.class.tire.mapping.empty?
            instance.to_hash.reject {|key,_| key.to_s == 'id' || key.to_s == 'type' }.to_json
          else
            mapping = instance.class.tire.mapping
            hash = instance.to_hash.reject { |key, value| ! mapping.keys.map(&:to_s).include?(key.to_s) }
            mapping.each do |key, options|
              case options[:as]
                when String
                  hash[key] = instance.instance_eval(options[:as])
                when Proc
                  hash[key] = instance.instance_eval(&options[:as])
                else
                  hash[key] = options[:as]
              end if options[:as]
            end
            hash.to_json
          end
        end
def to_indexed_json if instance . class . tire . mapping . empty? instance . to_hash . reject { | key , _ | key . to_s == 'id' || key . to_s == 'type' } . to_json else mapping = instance . class . tire . mapping hash = instance . to_hash . reject { | key , value | ! mapping . keys . map ( & :to_s ) . include? ( key . to_s ) } mapping . each do | key , options | case options [ :as ] when String hash [ key ] = instance . instance_eval ( options [ :as ] ) when Proc hash [ key ] = instance . instance_eval ( & options [ :as ] ) else hash [ key ] = options [ :as ] end if options [ :as ] end hash . to_json end end
The default JSON serialization of the model, based on its `#to_hash` representation.
The default JSON serialization of the model based on its ` #to_hash ` representation .
# Reject the id and type keys # Reject keys not declared in mapping # Evalute the `:as` options