Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom init on test/development mode in Grails

Tags:

grails

groovy

I want to run specific login in BootStrap class depending on development or test mode is currently used.

How can I do this?

like image 799
yura Avatar asked Dec 15 '10 16:12

yura


2 Answers

From the documentation:

class Bootstrap {
    def init = { ServletContext ctx ->
        environments {
            production {
                // prod initialization
            }
            test {
                // test initialization
            }
            development {
                // dev initialization
            }
        }
    }
    ...
}
like image 98
Rob Hruska Avatar answered Sep 23 '22 01:09

Rob Hruska


import grails.util.Environment

class BootStrap {

    def init = { servletContext ->

        def currentEnv = Environment.current

        if (currentEnv == Environment.DEVELOPMENT) {
            // do custom init for dev here

        } else if (currentEnv == Environment.TEST) {
            // do custom init for test here

        } else if (currentEnv == Environment.PRODUCTION) {
            // do custom init for prod here
        }
     }

     def destroy = {
     }
}
like image 26
Dónal Avatar answered Sep 21 '22 01:09

Dónal