Giter Club home page Giter Club logo

onyx_ex's Introduction

OnyxEx

Onyx configuration reading library for Elixir

This Elixir library reads configuration YAML files as specified and used by the Onyx CLI tool. You can find the documentation for Onyx CLI here.

Usage

Create an onyx.yml file with onyx init

Include the dependency in your mix.exs

{:onyx_ex, github: "johnf9896/onyx_ex", tag: "0.1.0"}

Configure the dependency in config.exs

# format can be :map or :keyword. Default :map
# Specifies the type of complex configuration entries
#
# YAML:
# app:
#   config:
#     foo:
#       bar: xxxx
#       baz: yyyy
#
# Result:
# :map
#   OnyxEx.get!(:foo)
#   %{bar: "xxxx", baz: "yyyy"}
# :keyword
#   OnyxEx.get!(:foo)
#   [bar: "xxxx", baz: "yyyy"]
config :onyx_ex, app: :my_app, format: :keyword

Sample configuration files

onyx.yml:

name: example
description: An example app
container: none
umbrella: true
include:
  - onyx.priv.yml
app:
  config:
    db:
      name: db
      pass: secret
      user: user
      port: 80
      host: localhost
    key: XXXX
apps:
  models:
    config:
      baz: foo
  core:
    config:
      foo: bar
runner:
  valid: []
  default: []

onyx.priv.yml:

app:
  config:
    db:
      port: 8080
    key2: YYYY
apps:
  models:
    config:
      baz: fuz
      ff: sd
  core:
    config:
      haz: faa

Getting configuration entries

OnyxEx.get(:models, :baz, nil) # fuz
OnyxEx.get(:baz, "default") # fuz, will take the app from config.exs
OnyxEx.get(:bazz, "default") # default
OnyxEx.get!(:db) # Will fallback to app. Will raise error if not found. Returns a map or a keyword list depending on :format
OnyxEx.get!({:db, :port}) # 8080
OnyxEx.get!({:db, :pass}) # secret

You can also use sigils

import OnyxEx

~o/db/ # Same as OnyxEx.get(:db, nil)
~o/db|pass/ # Same as OnyxEx.get({:db, :pass}, nil)
~o/db/models # Same as OnyxEx.get(:models, :db, nil)
~O/db/ # Same as OnyxEx.get!(:db)

License


Copyright 2018 Jhon Pedroza

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

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.