<commit_before>package grails.plugin.mergeconfig

import org.codehaus.groovy.grails.commons.GrailsApplication
import static grails.plugin.mergeconfig.ConfigurationType.STRING

class Configuration {

  String key
  String value
  String description
  ConfigurationType type

  def configurationService
  static transients = ['configurationService']

  static constraints = {
    description nullable: true
    key unique: true
  }

  static mapping = {
    // Key is a reserved word in some SQL dialects
    key column: "key_name"
  }

  Object getValueAsType() {
    configurationService.getValueWithType(this)
  }

  Map toMap() {
    def config = [
        id: id,
        key: key,
        value: valueAsType,
        description: description ?: "None",
        type: type?.toMap()
    ]
    return config
  }

  static void merge(GrailsApplication application) {
    application.config.merge(Configuration.reload(application))
    application.config.merge(Configuration.update())
  }

  static void remove(GrailsApplication application, config) {
    config?.delete(flush: true)
    application.config.remove(config?.key)
    Configuration.merge(application)
  }

  private static ConfigObject update() {
    def configObject = new ConfigObject()
    Configuration.all.each { Configuration config ->
      def string = (config.type == STRING) ? "${config?.key} = \"${config?.value}\"" : "${config?.key} = ${config?.value}\n"
      configObject.merge(new ConfigSlurper().parse(string))
    }
    configObject
  }

  private static ConfigObject reload(GrailsApplication application) {
    ConfigObject config = new ConfigObject()
    config.merge(new ConfigSlurper().parse(application.classLoader.loadClass("Config")))
    application.config.locations.each { String location ->
      String configFile = location.split("file:")[0]
      config.merge(new ConfigSlurper().parse(new File(configFile).text))
    }
    config<commit_msg>Fix issue with creating List type.<commit_after>package grails.plugin.mergeconfig

import org.codehaus.groovy.grails.commons.GrailsApplication
import static grails.plugin.mergeconfig.ConfigurationType.STRING

class Configuration {

  String key
  String value
  String description
  ConfigurationType type

  def configurationService
  static transients = ['configurationService']

  static constraints = {
    description nullable: true
    key unique: true
  }

  static mapping = {
    // Key is a reserved word in some SQL dialects
    key column: "key_name"
  }

  Object getValueAsType() {
    configurationService.getValueWithType(this)
  }

  Map toMap() {
    def config = [
        id: id,
        key: key,
        value: valueAsType,
        description: description ?: "None",
        type: type?.toMap()
    ]
    return config
  }

  static void merge(GrailsApplication application) {
    application.config.merge(Configuration.reload(application))
    application.config.merge(Configuration.update())
  }

  static void remove(GrailsApplication application, config) {
    config?.delete(flush: true)
    application.config.remove(config?.key)
    Configuration.merge(application)
  }

  private static ConfigObject update() {
    def configObject = new ConfigObject()
    Configuration.all.each { Configuration config ->
      def string = (config.type == STRING) ? "${config?.key} = \"${config?.valueAsType}\"" : "${config?.key} = ${config?.valueAsType}\n"
      configObject.merge(new ConfigSlurper().parse(string))
    }
    configObject
  }

  private static ConfigObject reload(GrailsApplication application) {
    ConfigObject config = new ConfigObject()
    config.merge(new ConfigSlurper().parse(application.classLoader.loadClass("Config")))
    application.config.locations.each { String location ->
      String configFile = location.split("file:")[0]
      config.merge(new ConfigSlurper().parse(new File(configFile).text))
    }
    config
{'fraction_non_alphanumeric': 0.10689566777749294, 'fraction_numerical': 0.0005126890540886952, 'mean_word_length': 3.639714625445898, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7487071', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1043, 'n_words': 248}