Reputation: 9279
Is there a way to do what theConfig.groovy
file does, but during the code execution...
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 something with that sintax???
Upvotes: 5
Views: 3129
Reputation: 171084
Found this blog post which shows one possible solution using 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'
}
}
}
}
Upvotes: 16