Project

setty

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Mini application configuration for Rails projects.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
= 3.0

Runtime

 Project Readme

Gem Version Code Climate Build Status Code coverage

Setty

Mini application configuration for Rails projects.

Installation

Add this line to your application's Gemfile:

gem 'setty'

And then execute:

$ bundle

Usage

The config files will be automatically loaded after rails loads.

Example:

# config/settings.yml
production:
  secret_token: "<%= ENV['SECRET_TOKEN'] %>"
  ssl_only: true

developement:
  secret_token: "blablablabla"
  ssl_only: false
# config/settings/products.yml
production:
  minumum_photos_count: 4

development:
  minumum_photos_count: 1

test:
  minumum_photos_count: 0

This gives you the Settings object:

# in development

Settings.secret_token                  #=> "blablablabla"
Settings.secret_token?                 #=> true
Settings.ssl_only                      #=> false
Settings.ssl_only?                     #=> false
Settings.products.minumum_photos_count #=> 1

You can find example of most important features and plugins - here.

Features:

  • Configurable
  • Environment dependent
  • Interpolation
  • Nested settings
  • Reloading settings

Configurable

# application.rb
module MyApp
  class Application < Rails::Application
    # ... code ... code ...
    config.setty.settings_object_name    = 'Settings'  # => settings will be loaded in `Settings`
    config.setty.settings_path           = 'settings'  # => extracts settings from `config/settings/*` and `config/settings.yml`
    config.setty.settings_environment    = Rails.env   # => enviroment name (defaults to Rails.env)
  end
end

Environment dependent

# validations.yml
development:
  require_user_to_belong_to_account: true

test:
  require_user_to_belong_to_account: false

production:
  require_user_to_belong_to_account: true

Depending on your Rails environment:

# in development
Settings.validations.require_user_to_belong_to_account  #=> true
Settings.validations.require_user_to_belong_to_account? #=> true

# in test
Settings.validations.require_user_to_belong_to_account  #=> false
Settings.validations.require_user_to_belong_to_account? #=> false

Interpolation

production:
  archives_path: "<%= Rails.root.join('archives').realpath %>"

Plays nicely with Dotenv

# s3.yml
production:
  access_key_id: "<%= ENV['S3_ACCESS_KEY'] %>"
  secret_access_key: "<%= ENV['S3_SECRET_KEY'] %>"
  region: "eu-west-1"
  bucket: "my-app"
# in production
Settings.s3.access_key_id     #=> S3_ACCESS_KEY from `.env.production`
Settings.s3.secret_access_key #=> S3_SECRET_KEY from `.env.production`

Nested Settings

The following yaml files:

config/settings.yml
config/settings/validations.yml
config/settings/validations/product.yml
config/settings/validations/category.yml

Will produce the following settings options hierarchy:

Settings
Settings.validations
Settings.validations.product
Settings.validations.category

Reloading

You can reload the current settings by calling:

Settings.reload

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

MIT License