Class: Rubix::Application

Inherits:
Model
  • Object
show all
Includes:
Rubix::Associations::BelongsToHost
Defined in:
lib/rubix/models/application.rb

Instance Attribute Summary collapse

Attributes inherited from Model

#id, #properties

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rubix::Associations::BelongsToHost

#host, #host=, #host_id, #host_id=

Methods inherited from Model

all, all_params, all_request, #before_destroy, #before_update, #create, #create_request, #destroy, #destroy_params, #destroy_request, each, find, find_or_create, find_request, get_params, id_field, #id_field, list, #new_record?, request, #request, #resource_name, resource_name, #save, #update, #update_request, #validate, web_request, zabbix_name

Methods included from Logs

#debug, #error, #fatal, #info, #warn

Constructor Details

#initialize(properties = {}) ⇒ Application

Properties & Finding ==



9
10
11
12
13
14
15
# File 'lib/rubix/models/application.rb', line 9

def initialize properties={}
  super(properties)
  @name    = properties[:name]
  
  self.host_id = properties[:host_id]
  self.host    = properties[:host]
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



17
18
19
# File 'lib/rubix/models/application.rb', line 17

def name
  @name
end

Class Method Details

.build(app) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rubix/models/application.rb', line 47

def self.build app
  params = {
    :id   => app[id_field].to_i,
    :name => app['name']
  }

  # use the host id if available, else use the template id
  if app['hosts'] && app['hosts'].first && app['hosts'].first['hostid']
    params[:host_id] = app['hosts'].first['hostid'].to_i
  else
    params[:host_id] = app['templateid']
  end
  new(params)
end

.find_params(options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/rubix/models/application.rb', line 37

def self.find_params options={}
  super().merge({
                  :hostids => [options[:host_id]],
                  :filter => {
                    :name   => options[:name],
                    id_field => options[:id]
                  }
                })
end

Instance Method Details

#create_paramsObject

Requests ==



29
30
31
# File 'lib/rubix/models/application.rb', line 29

def create_params
  {:name => name, :hostid => host_id}
end

#update_paramsObject



33
34
35
# File 'lib/rubix/models/application.rb', line 33

def update_params
  { id_field => id, :name => name, :hosts => {:hostid => host_id}}
end