Giter VIP home page Giter VIP logo

config-kit's Introduction

ConfigKit

With this project you can easily create a config file.

Using ConfigKit in your plugin

Maven

<dependencies>
 <dependency>
    <groupId>world.avionik</groupId>
    <artifactId>config-kit</artifactId>
    <version>1.0.1</version>
    <scope>provided</scope>
  </dependency>
</dependencies>

Gradle

dependencies {
    compileOnly 'world.avionik:config-kit:1.0.1'
}

How to create a ConfigLoader

First of all, you need to decide which format you want to use. We support Json and Yaml. Then you need a class that you save in the appropriate format. Then you have to think about which format you want to use. For example, let's take this config:

class TestConfig(
    val firstString: String,
    val secondList: List<String>
)

Note: If you want to save as a Yaml file, you have to write via the class @Serialisable to avoid errors.

And this is how you can create the ConfigLoader

class TestConfigLoader : ConfigLoader<TestConfig>(
    File("config.json"), // Here you can set where the file should be saved
    JsonFileFormatter(TestConfig::class.java), // Here you have to adapt your format. There are JsonFileFormatter and YamlFileFormatter
    { TestConfig("123", listOf("abc", "def")) }
)

How to use the ConfigLoader

Once you have successfully created a ConfigLoader, various methods are available to you. These include configLoader.load(), which is used to retrieve the configuration. If you want to save a configuration, you can use the configLoader.save(config) method.

How to create the MultipleConfigLoader

Everything remains the same as with the ConfigLoader, but with one exception. The class needs the nameable implantation so that the files can be selected.

class KitConfig(
    val name: String,
    val secondList: List<String>
) : Nameable {
    override fun getName(): String = this.name
}

Note: If you want to save as a Yaml file, you have to write via the class @Serialisable to avoid errors.

And this is how you can create the MultipleConfigLoader

class TestConfigLoader : MultipleConfigLoader<KitConfig>(
    File("config/kits"), // All files are saved in this directory
    JsonFileFormatter(KitConfig::class.java) // Here you have to adapt your format. There are JsonFileFormatter and YamlFileFormatter
)

How to use the MultipleConfigLoader

With configLoader.loadAll() you can get all configs from this directory.

config-kit's People

Contributors

niklasnieberler avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.