Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Library for flexible specifying of application settings different ways
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.gitignore
Gemfile
LICENSE_MIT
README.md
Rakefile
sexy_settings.gemspec

README.md

Sexy Settings

Dependency Status

Application settings are specified in a flexible way.

What is Sexy Settings?

It is a Ruby-based library used to specify application settings in different ways:

  • Using the YAML file (default and custom settings).
  • Using the command line.

What's new in 0.0.1

First version with the base functionality.

Getting Started

Prerequisites

It was tested with Ruby 1.9.2 but we expect it to also work with other Ruby versions

Installation

gem install sexy_settings

Configuration

Create 2 configuration files, one for default settings and the other one – for custom settings, e.g.:

config\
    default.yaml
    overwritten.yaml

Insert the following code to the boot executable ruby file:

 require 'sexy_settings'

 SexySettings.configure do |config|
   config.path_to_default_settings = File.expand_path("config.yaml", File.join(File.dirname(__FILE__), '..', 'config')) # 'default.yml' by default
   config.path_to_custom_settings = File.expand_path("overwritten.yaml", File.join(File.dirname(__FILE__), '..', 'config')) # 'custom.yml' by default
   config.path_to_project = File.dirname(__FILE__) # '.' by default
   config.env_variable_with_options = 'OPTIONS' # 'OPTS' by default
   cmd_line_option_delimiter = '$$$' # ',' by default
 end

Specify a shortcut method for the Settings object:

 def settings
   SexySettings::Base.instance()
 end

Usage

There are 4 possible settings values. The priority ranks with respect to the settings location are as follows:

command line < custom < default < nil(in case setting was not specified anywhere)

Thus, specifying some setting in the command line will override the same setting value specified in the <default config file> or <custom config file>

Example:

default.yaml

  foo: bar
  foo1: default ${foo}
  foo2: default value

overwritten.yaml

  foo1: custom ${foo}

Set an environment variable:

OPTIONS="foo2=10$$$foo3=:hi$$$foo4=true"

puts settings.foo # returns 'bar'
puts settings.foo1 # returns 'custom foo'
puts settings.foo2 # returns 10
puts settings.foo3 # returns :hi
puts settings.foo4 # returns true

Hints

  • Add <default config file> under the version control system.
  • Add <custom config file> to ignore the list.
  • Use the command line with an Environment Variable for fast specifying setting in your Continuous Integration System.
  • Use the following code to output all settings as a pretty formatted text:
puts settings.as_formatted_text
Something went wrong with that request. Please try again.