cirandas.net

ref: master

plugins/elasticsearch/lib/elasticsearch_plugin/entities.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Elasticsearch
  module Entities

    class Result < Api::Entity
      root "results","result"

      expose :type do |object, options|
        options[:types].detect { |type| type.to_s.upcase if object.is_a? (type.to_s.classify.constantize) }
      end

      expose :id
      expose :name

      expose :author, if: lambda { |object,options| object.respond_to? 'author'}  do |object, options|
        object.author.present? ? object.author.name : ""
      end

      expose :description, if: lambda { |object,options| object.respond_to? 'description'}  do |object, options|
        object.description.present? ? object.description : ""
      end

      expose :abstract, if: lambda { |object,options| object.respond_to? 'abstract'}  do |object, options|
        object.abstract.present? ? object.abstract : ""
      end

      expose :created_at, :format_with => :timestamp
      expose :updated_at, :format_with => :timestamp
    end

  end
end