Class: Elastomer::Client::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/elastomer/client/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, name) ⇒ Template

Create a new template client for making API requests that pertain to template management.

client - Elastomer::Client used for HTTP requests to the server name - The name of the template as a String



19
20
21
22
# File 'lib/elastomer/client/template.rb', line 19

def initialize( client, name )
  @client = client
  @name   = name
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



24
25
26
# File 'lib/elastomer/client/template.rb', line 24

def client
  @client
end

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/elastomer/client/template.rb', line 24

def name
  @name
end

Instance Method Details

#create(template, params = {}) ⇒ Object

Create the template on the cluster. See www.elasticsearch.org/guide/reference/api/admin-indices-templates/

template - The template as a Hash or a JSON encoded String params - Parameters Hash

Returns the response body as a Hash



50
51
52
53
# File 'lib/elastomer/client/template.rb', line 50

def create( template, params = {} )
  response = client.put '/_template/{template}', update_params(params, :body => template, :action => 'template.create')
  response.body
end

#defaultsObject

Internal: Returns a Hash containing default parameters.



80
81
82
# File 'lib/elastomer/client/template.rb', line 80

def defaults
  { :template => name }
end

#delete(params = {}) ⇒ Object

Delete the template from the cluster. See www.elasticsearch.org/guide/reference/api/admin-indices-templates/

params - Parameters Hash

Returns the response body as a Hash



61
62
63
64
# File 'lib/elastomer/client/template.rb', line 61

def delete( params = {} )
  response = client.delete '/_template/{template}', update_params(params, :action => 'template.delete')
  response.body
end

#exists?Boolean Also known as: exist?

Returns true if the template already exists on the cluster.

Returns:

  • (Boolean)


27
28
29
# File 'lib/elastomer/client/template.rb', line 27

def exists?
  client.cluster.templates.key? name
end

#get(params = {}) ⇒ Object

Get the template from the cluster. See www.elasticsearch.org/guide/reference/api/admin-indices-templates/

params - Parameters Hash

Returns the response body as a Hash



38
39
40
41
# File 'lib/elastomer/client/template.rb', line 38

def get( params = {} )
  response = client.get '/_template/{template}', update_params(params, :action => 'template.get')
  response.body
end

#update_params(params, overrides = nil) ⇒ Object

Internal: Add default parameters to the ‘params` Hash and then apply `overrides` to the params if any are given.

params - Parameters Hash overrides - Optional parameter overrides as a Hash

Returns a new params Hash.



73
74
75
76
77
# File 'lib/elastomer/client/template.rb', line 73

def update_params( params, overrides = nil )
  h = defaults.update params
  h.update overrides unless overrides.nil?
  h
end