Module: Elastics::Model::HelperMethods

Defined in:
lib/elastics/model/helper_methods.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/elastics/model/helper_methods.rb', line 4

def self.included(base)
  base.class_eval do
    extend ClassMethods

    # don't override to_elastics method, if it already exists
    if !instance_methods.include?(:to_elastics) && instance_methods.include?(:as_json)
      alias_method :to_elastics, :as_json
    end
  end
end

Instance Method Details

#delete_elasticsObject



92
93
94
95
# File 'lib/elastics/model/helper_methods.rb', line 92

def delete_elastics
  self.class.request_elastics(method: :delete, id: id)
rescue NotFound
end

#index_elasticsObject



80
81
82
# File 'lib/elastics/model/helper_methods.rb', line 80

def index_elastics
  self.class.request_elastics(method: :post, id: id, body: to_elastics)
end

#update_elastics(data) ⇒ Object



84
85
86
# File 'lib/elastics/model/helper_methods.rb', line 84

def update_elastics(data)
  self.class.request_elastics(method: :post, id: "#{id}/_update", body: data)
end

#update_elastics_doc(fields) ⇒ Object



88
89
90
# File 'lib/elastics/model/helper_methods.rb', line 88

def update_elastics_doc(fields)
  update_elastics(doc: fields)
end