Class: ElasticSearch::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_search/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Request

Returns a new instance of Request.



5
6
7
8
9
10
11
12
13
# File 'lib/elastic_search/request.rb', line 5

def initialize(options = {})
  @method = options[:method] ? options[:method].to_sym : :get
  @index = options[:index]
  @type = options[:type]
  @id = options[:id]
  @action = options[:action]
  @parameters = options[:parameters]
  @body = options[:body]
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



3
4
5
# File 'lib/elastic_search/request.rb', line 3

def action
  @action
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/elastic_search/request.rb', line 3

def id
  @id
end

#indexObject (readonly)

Returns the value of attribute index.



3
4
5
# File 'lib/elastic_search/request.rb', line 3

def index
  @index
end

#methodObject (readonly)

Returns the value of attribute method.



3
4
5
# File 'lib/elastic_search/request.rb', line 3

def method
  @method
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/elastic_search/request.rb', line 3

def type
  @type
end

Instance Method Details

#bodyObject



22
23
24
# File 'lib/elastic_search/request.rb', line 22

def body
  @encoded_body ||= @body.is_a?(String) ? @body : @body.to_json
end

#parametersObject



15
16
17
18
19
20
# File 'lib/elastic_search/request.rb', line 15

def parameters
  @stringified_parameters ||= @parameters.inject({}) do |options, (key, value)|
    options[key.to_s] = value.to_s
    options
  end if @parameters
end

#pathObject



26
27
28
29
30
# File 'lib/elastic_search/request.rb', line 26

def path
  components = [@index, @type, @id]
  components << "_#{@action.to_s}" if @action
  "/#{components.compact.join("/")}"
end