Class: IndexTank::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/indextank/function.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(function_url, index, definition) ⇒ Function

Returns a new instance of Function.



7
8
9
10
11
12
13
14
15
# File 'lib/indextank/function.rb', line 7

def initialize(function_url, index, definition)
  @uri        = "#{function_url}/#{index}"
  @index      = index
  @definition = definition
  @conn = IndexTank.setup_connection(@uri) do |faraday|
    # Function and Document have the same Response statuses
    faraday.use IndexTank::DocumentResponseMiddleware
  end
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



5
6
7
# File 'lib/indextank/function.rb', line 5

def definition
  @definition
end

#indexObject (readonly)

Returns the value of attribute index.



5
6
7
# File 'lib/indextank/function.rb', line 5

def index
  @index
end

#uriObject (readonly)

Returns the value of attribute uri.



5
6
7
# File 'lib/indextank/function.rb', line 5

def uri
  @uri
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
41
42
# File 'lib/indextank/function.rb', line 38

def ==(other)
  self.uri == other.uri and
    self.index == other.index
    self.definition == other.definition
end

#add(options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/indextank/function.rb', line 17

def add(options = {})
  raise MissingFunctionDefinition unless self.definition

  options.merge!(:definition => self.definition)
  response = @conn.put do |req|
    req.url ''
    req.body = options.to_json
  end

  true
end

#delete(options = {}) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/indextank/function.rb', line 29

def delete(options = {})
  resp = @conn.delete do |req|
    req.url ''
    req.body = options.to_json
  end

  true
end