File: method.erb

package info (click to toggle)
ruby-elasticsearch 7.17.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,820 kB
  • sloc: ruby: 44,308; sh: 16; makefile: 2
file content (73 lines) | stat: -rw-r--r-- 3,056 bytes parent folder | download | duplicates (2)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

module Elasticsearch
<%- if @current_api == :xpack -%>
  <%= '  '*(@namespace_depth) %>module XPack
<%- end %>
<%= '  '*(@namespace_depth) %>module API
<%- @module_namespace.each_with_index do |name, i| -%>
  <%= '  '*i %>module <%= module_name_helper(name) %>
<%- end -%>
<%= '  '*(@namespace_depth+2) %>module Actions
<%= ERB.new(File.new("./thor/templates/_documentation_top.erb").read, trim_mode: '-').result(binding) -%>
<%# Method definition -%>
<%= '  '*(@namespace_depth+3) -%>def <%= @method_name %>(arguments = {})
<%- if @endpoint_name == 'create' -%>
  <%= '  '*(@namespace_depth+3) %>if arguments[:id]
  <%= '  '*(@namespace_depth+3) %>  index arguments.update op_type: 'create'
  <%= '  '*(@namespace_depth+3) %>else
  <%= '  '*(@namespace_depth+3) %>  index arguments
  <%= '  '*(@namespace_depth+3) %>end
  <%= '  '*(@namespace_depth+2) %>end
<%- else -%>
  <%- if @method_name == 'get_field_mapping' %>
    _fields = arguments.delete(:field) || arguments.delete(:fields)
    raise ArgumentError, "Required argument 'field' missing" unless _fields
  <%- else -%>
    <%- @required_parts.each do |required| %><%# Arguments -%>
      <%= '  '*(@namespace_depth+3) + "raise ArgumentError, \"Required argument '#{required}' missing\" unless arguments[:#{required}]" + "\n" -%>
    <%- end -%>
    <%- end -%>
    headers = arguments.delete(:headers) || {}
    <%- # Method setup -%>
    <%= ERB.new(File.new("./thor/templates/_method_setup.erb").read, trim_mode: '-').result(binding) %>
    <%- # Perform request -%>
    <%= ERB.new(File.new("./thor/templates/_perform_request.erb").read, trim_mode: '-').result(binding) %>
<%- end -%>
<%- if @method_name.match?(/^exists\S*/) -%>
  alias_method :<%= @method_name %>?, :<%= @method_name %>
<%- end -%>
<%- if @method_name == 'termvectors' %>

  # Deprecated: Use the plural version, {#termvectors}
  #
  def termvector(arguments={})
    termvectors(arguments.merge endpoint: '_termvector')
  end
<%- end -%>
<%# Params Registry Template -%>
<%- unless @endpoint_name == 'create' -%>
  <%= ERB.new(File.new("./thor/templates/_params_registry.erb").read, trim_mode: '-').result(binding) %>
<%- end -%>

<%- @namespace_depth.downto(1) do |i| -%>
<%= '  '*(i-1) %>end
<%- end if @namespace_depth > 0 -%>
    end
  end
end