0.0
No commit activity in last 3 years
No release in over 3 years
App::Config is yet another library for load/save app config files.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 0
>= 0
 Project Readme

App::Config

Yet another library for load/save app config files.

Features

  • Read the configuration files (default, startup, modified) in order and apply by overwriting.

  • The modified configuration can be saved as a file in a given directory.

  • File type Supports Ruby scripts, YAML and JSON.

Installation

Add this line to your app’s Gemfile:

gem 'app-configs'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install app-configs
or
$ gem install -l app-configs-x.x.x.gem

Usage

Example

require  "app/config"

# initial load. default search paths: "./config/defaults:./config:./var"
config  =  App::Config.new

puts  config["test"]["lastdate"]

# update content.
config["test"]["lastdate"]  =  Time.now.to_s
pp  config["test"]

# save section changes. (default: "./var")
config.save("test")
pp  config["test"]

# load section.
config.load("test")
pp  config["test"]

# remove modification and load original section
config.reset("test")
pp  config["test"]

# reload all section.
config.reload
pp  config

Reference

Create a new App::Config::* with conditions.

App::Config.new( type = nil, root: nil, path: nil )
App::Config::RUBY.new( root: nil, path: nil )
App::Config::YAML.new( root: nil, path: nil )
App::Config::JSON.new( root: nil, path: nil )
  • Result:

    • App::Config::{RUBY,YAML,JSON} object.

  • Parameter:

    • type: Configulation file type. RUBY, YAML, or JSON. (default: YAML)

    • root: App root directory. (default: ".")

    • path: The directories for search and load file(s). (default: "$ROOT/config/defaults/:$ROOT/config:$ROOT/var")

Reload all section(s).

App::Config::RUBY#reload( root: nil, path: nil )
App::Config::YAML#reload( root: nil, path: nil )
App::Config::JSON#reload( root: nil, path: nil )
  • Result:

    • nil.

  • Parameter:

    • root: App root directory. (default: ".")

    • path: The directories for search and load file(s). (default: "$ROOT/config/defaults/:$ROOT/config:$ROOT/var")

Load the section.

App::Config::RUBY#load( section )
App::Config::YAML#load( section )
App::Config::JSON#load( section )
  • Result:

    • nil.

  • Parameter:

    • section: Section name for load.

Save section changes. (default: "./var")

App::Config::RUBY#save( section )
App::Config::YAML#save( section )
App::Config::JSON#save( section )
  • Result:

    • nil.

  • Parameter:

    • section: Section name for save.

Remove modification and load original section

App::Config::RUBY#reset( section )
App::Config::YAML#reset( section )
App::Config::JSON#reset( section )
  • Result:

    • nil.

  • Parameter:

    • section: Section name for reset.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/arimay/app-configs.

License

The gem is available as open source under the terms of the MIT License.

Copyright (c) ARIMA Yasuhiro <arima.yasuhiro@gmail.com>