Class: Ey::Core::Client::DatabaseService

Inherits:
Model
  • Object
show all
Extended by:
Associations
Defined in:
lib/ey-core/models/database_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Associations

assoc_accessor, assoc_coverage, assoc_reader, assoc_writer, associations, collection_reader

Methods inherited from Model

#destroy, range_parser, #save, #to_s, #update!, #url

Instance Attribute Details

#database_serverObject

TODO:

remove me next major revision



18
19
20
# File 'lib/ey-core/models/database_service.rb', line 18

def database_server
  @database_server
end

Instance Method Details

#destroy!Object



49
50
51
# File 'lib/ey-core/models/database_service.rb', line 49

def destroy!
  connection.requests.new(self.connection.destroy_database_service("id" => self.id).body["request"])
end

#save!Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ey-core/models/database_service.rb', line 20

def save!
  requires :name, :provider_id

  server_info  = self.servers.map { |c| c.is_a?(Ey::Core::Client::DatabaseServer) ? c.attributes : c }

  server_info += [database_server] if database_server

  if server_info.size > 1
    raise ArgumentError, "only one server can be specified"
  elsif server_info.size < 1
    raise ArgumentError, "you must specify at least one server dude"
  end

  params = {
    "url"              => self.collection.url,
    "provider"         => self.provider_id,
    "database_server"  => server_info.first,
    "database_service" => {
      "name"          => self.name,
      "service_level" => self.service_level,
    },
  }

  if new_record?
    self.connection.requests.new(self.connection.create_database_service(params).body["request"])
  else raise NotImplementedError
  end
end