Class: RubyYacht::Database::DSL

Inherits:
Object
  • Object
show all
Extended by:
RubyYacht::DSL::Base::ClassMethods
Includes:
RubyYacht::DSL::Base
Defined in:
lib/ruby_yacht/dsl/database.rb

Overview

This class provides a DSL for configuring a database.

You can access this DSL by calling database within RubyYacht::Project::DSL. It will create a RubyYacht::Database

Instance Method Summary collapse

Methods included from RubyYacht::DSL::Base::ClassMethods

add_attribute, add_boolean, add_generic_attribute, add_list, add_object, add_object_list, all_attributes, copied_attributes, created_type, creates_object, custom_attribute_method, default_values, required_attributes

Methods included from RubyYacht::DSL::Base

#create_object, #load_custom_attributes, #run

Constructor Details

#initialize(name, server_type = nil) ⇒ DSL

This initializer starts the DSL for the database.

Parameters

  • name: String The name of the database.
  • server_type: Symbol The type of database server this is.

51
52
53
54
55
# File 'lib/ruby_yacht/dsl/database.rb', line 51

def initialize(name, server_type = nil)
  @name = name
  @server_type = server_type
  load_custom_attributes
end

Instance Method Details

#check_required_attributesObject

This method checks that all of the required attributes have been set on the object.

If they haven't, this will raise an exception.

It also checks that the server type has been defined in the configuration.


101
102
103
104
105
106
107
# File 'lib/ruby_yacht/dsl/database.rb', line 101

def check_required_attributes
  super
  server_type = RubyYacht.configuration.find_server_type(@server_type)
  unless server_type && server_type.container_type == :database
    raise "Database has invalid server type `#{@server_type}`"
  end
end

#container_labelObject

:method: container_label You can call container_label 'mysql' to give this database a container name that is (project)-mysql.


90
# File 'lib/ruby_yacht/dsl/database.rb', line 90

add_attribute :container_label, :database

#hostObject

:method: host You can call host 'db.test.com' to set the database's host.


60
# File 'lib/ruby_yacht/dsl/database.rb', line 60

add_attribute :host

#passwordObject

:method: password You can call password 'testpass' to tell the apps to connect to the password testpass.


84
# File 'lib/ruby_yacht/dsl/database.rb', line 84

add_attribute :password

#usernameObject

:method: username You can call username 'db-user' to tell the apps to connect to the database under the name db-user.


78
# File 'lib/ruby_yacht/dsl/database.rb', line 78

add_attribute :username