Coder Social home page Coder Social logo

setler's Introduction

Setler

Setler is a Gem that lets one easily implement the “Feature Flags” pattern, or add settings to individual models. This is a cleanroom implementation of what the ‘rails-settings’ gem does. It’s been forked all over the place, and my favorite version of it doesn’t have any tests and doesn’t work with settings associated with models.

Setup

Install the gem by adding this to your Gemfile:

gem "setler"

Generate the model:

rails g setler <model_name>

Run the migration:

rake db:migrate

Usage

Create/Update settings:

# Method calls and []= are synonymous
Featureflags.bacon_dispenser_enabled = true
Settings[:allowed_meats] = ['bacon', 'crunchy bacon']

Read settings:

Featureflags.bacon_dispenser_enabled # true
Settings[:allowed_meats].include?('bacon')  # true

Destroy them:

Featureflags.destroy :bacon_dispenser_enabled
Settings.destroy :allowed_meats

List all:

Featureflags.all
Settings.all

Set defaults in an initializer with something like:

Featureflags.defaults[:bacon_dispenser_enabled] = false
Settings.defaults[:allowed_meats] = ['itsnotbacon']

To revert to the default after changing a setting, destroy it. Note: Updating the setting to nil or false no longer makes it the default setting (> 0.0.6), but changes the setting to nil or false.

Add them to any ActiveRecord object:

class User < ActiveRecord::Base
  has_setler as: :settings
end

Then you get:

user = User.first
user.settings.favorite_meat = :bacon
user.settings.favorite_meat  # :bacon
user.settings.all # { "favorite_meat" => :bacon }

TODO: And look em up:

User.with_settings_for('favorite_meat') # => scope of users with the favorite_meat setting

Gem Development

Getting started is pretty straightforward:

1. Check out the code:  `git clone git://github.com/ckdake/setler.git`
2. Bundle install:  `bundle install`
3. Run the tests and make sure they all pass and code coverage is still 100%:  `rake test`

If you’d like to contribute code, make your changes and submit a pull request that includes appropriate tests

For building the gem: ‘rake build` and to release a gem to github and Rubygems: `rake release`

setler's People

Contributors

ckdake avatar alindeman avatar stevenharman avatar uqus avatar rheaton avatar

Watchers

Tony Marschall avatar Syafikli Musyafako avatar James Cloos 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.