Project

togglify

0.0
No commit activity in last 3 years
No release in over 3 years
A Rubygem that allows you to easily enable/disable parts of your ruby code.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.2.1
>= 0
~> 1.8.4
~> 3.12
~> 2.11.0
 Project Readme

togglify

A simple Ruby gem that allows you to toggle (enable/disable) blocks of code for Rails.

Installation

Add it to your Gemfile

gem 'togglify'

And run bundle install

$ bundle install

Thats it your ready to start toggling!

Usage

Anywhere in your code you can add a togglify block giving it a name. Like this one for example

Togglify(:sample_name) do
  puts "This will be output to the rails log"
end

By default all toggles are enabled, meaning that any code put in those blocks will be executed. So when this block of code gets ran it will output the puts statement. Now to disable this block of code and any block of cade with the tag :sample_name you can run the following rake command.

# In ZSH  you will have to escape the square brackets with a \ or prepend the rake command
# with noglob
$ rake togglify:disable[sample_name]

Any Togglify block with the name :sample_name is now disabled in the development environment. To disable it in other environments append the command with RAILS_ENV=environment for example to disable these blocks in the test environment you can run

$ rake togglify:disable[sample_name] RAILS_ENV=test

Then to re-enable all the code blocks with the sample_name tag you can run

# Again, this defaults to development environment. append RAILS_ENV= for different environments
$ rake togglify:enable[sample_name]

You can programatically enable and disable toggles with the following code

Togglify.enable(:sample_name)
Togglify.disable(:sample_name)

Then to check the status of a toggle you can call

Togglify.enabled?(:sample_name) # Returns true or false
Togglify.enabled?(:sample_name) # Returns true or false
Togglify.status(:sample_name)   # Returns hash with status { :id => :sample_name, :development => :enabled}

Contributing to togglify

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
  • Fork the project.
  • Start a feature/bugfix branch.
  • Commit and push until you are happy with your contribution.
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright (c) 2012 Brady Love. See LICENSE.txt for further details.