Grails executes code for the environment

Is there a way to do what the file does Config.groovy, but at runtime ...
Something like:

class AController {
    def method () {
        withEnvironments {
            development {
               println 'This is execute just on development'
            }
            production {
               log.debug 'This is execute just on production'
            }
         }
     }
}

I know that I can achieve the same effect using if (Environment.current == 'development'), but is there anything with this sintax ???

+5
source share
1 answer

Found this blog post that shows one possible solution with Environment.executeForCurrentEnvironment:

import grails.util.Environment

class AController {
  def method() { 
    Environment.executeForCurrentEnvironment {
      development {
        println 'This is execute just on development'
      }
      production {
        log.debug 'This is execute just on production'
      }
    }
  }
}
+16
source

All Articles