Mongrel2::Config::

DSL

module

See DSL.rdoc for details on how to use this mixin.

Public Instance Methods

anchor
mimetype( extension, mimetype )

Set up a mimetype mapping between files with the given extension and mimetype.

# File lib/mongrel2/config/dsl.rb, line 147
def mimetype( extension, mimetype )
        Mongrel2::Config.init_database

        type = Mongrel2::Config::Mimetype.find_or_create( extension: extension )
        type.mimetype = mimetype
        type.save

        return type
end
anchor
mimetypes( hash )

Set some mimetypes en masse.

# File lib/mongrel2/config/dsl.rb, line 159
def mimetypes( hash )
        result = []

        Mongrel2::Config.db.transaction do
                hash.each do |ext, mimetype|
                        result << mimetype( ext, mimetype )
                end
        end

        return result
end
anchor
server( uuid, &block )

Create a Mongrel2::Config::Server with the specified uuid, evaluate the block (if given) within its context, and return it.

# File lib/mongrel2/config/dsl.rb, line 91
def server( uuid, &block )
        adapter = nil

        Mongrel2.log.info "Ensuring db is set up..."
        Mongrel2::Config.init_database

        Mongrel2.log.info "Entering transaction for server %p" % [ uuid ]
        Mongrel2::Config.db.transaction do

                # Set up the options hash with the UUID and reasonable defaults
                # for everything else
                server_opts = {
                        uuid:         uuid,
                    access_log:   "/logs/access.log",
                    error_log:    "/logs/error.log",
                    pid_file:     "/run/mongrel2.pid",
                    default_host: "localhost",
                    port:         8888,
                }

                Mongrel2.log.debug "Server [%s] (block: %p)" % [ uuid, block ]
                adapter = Adapter.new( Mongrel2::Config::Server, server_opts )
                adapter.instance_eval( &block ) if block

                Mongrel2.log.info "  saving server %p..." % [ uuid ]
                adapter.target.save
        end

        return adapter.target
end
anchor
setting( key, val )

Set the value of one of the 'Tweakable Expert Settings'

# File lib/mongrel2/config/dsl.rb, line 124
def setting( key, val )
        Mongrel2::Config.init_database
        setting = Mongrel2::Config::Setting.find_or_create( key: key )
        setting.value = val
        setting.save
end
anchor
settings( hash )

Set some 'Tweakable Expert Settings' en masse

# File lib/mongrel2/config/dsl.rb, line 133
def settings( hash )
        result = []

        Mongrel2::Config.db.transaction do
                hash.each do |key, val|
                        result << setting( key, val )
                end
        end

        return result
end