Sha256: 2deb652328ed509e0783d6f6151a39c421f33fc5b35a71be0b6e2962759a87c4

Contents?: true

Size: 1.42 KB

Versions: 5

Compression:

Stored size: 1.42 KB

Contents

module Rubix
  
  class Application < Model

    #
    # == Properties & Finding ==
    #

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

    def self.find_request options={}
      request('application.get', 'hostids' => [options[:host_id]], 'filter' => {'name' => options[:name], 'applicationid' => options[:id]}, "output" => "extend")
    end

    def self.build app
      params = {
        :id   => app['applicationid'].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
    
    def self.id_field
      'applicationid'
    end
    
    
    #
    # == Associations ==
    #

    include Associations::BelongsToHost
    
    #
    # == CRUD ==
    #
    
    def create_request
      request('application.create', 'name' => name, 'hostid' => host_id)
    end

    def update_request
      request('application.update', 'applicationid' => id, 'name' => name, 'hosts' => {'hostid' => host_id})
    end

    def destroy_request
      request('application.delete', [id])
    end
    
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubix-0.0.7 lib/rubix/models/application.rb
rubix-0.0.6 lib/rubix/models/application.rb
rubix-0.0.5 lib/rubix/models/application.rb
rubix-0.0.4 lib/rubix/models/application.rb
rubix-0.0.3 lib/rubix/models/application.rb