<commit_before>Gargoyle
--------

Gargoyle is a platform built on top of Django which allows you to switch functionality of your application on and off based on conditions.

Screenshot
=========

.. image:: http://dl.dropbox.com/u/116385/Screenshots/-egenorlfjki.png

Installation
============

Install it with pip (or easy_install)::

	pip install gargoyle

Config
======

If you dont have `Nexus <https://github.com/dcramer/nexus>`_ already enabled, you will need to do that first.

(Nexus is a replacement for your Django admin frontend, that works with django.contrib.admin)

Now you just need to add Gargoyle to your ``INSTALLED_APPS``::

	INSTALLED_APPS = (
	    ...
	    'gargoyle',
	)

Usage
=====

Gargoyle is typically used in two fashions. The first and simplest, is as a decorator. The decorator will automatically integrate with filters registered to the ``User`` model, as well as IP address::

	from gargoyle.decorators import switch_is_active
	
	@switch_is_active('my switch name')
	def my_view(request):
	    return 'foo'

The second use is with the ``is_active`` method. This allows you to perform validation on your own custom objects::

	from gargoyle import gargoyle
	
	def my_function(request):
	    if gargoyle.is_active('my switch name', request):
	        return 'foo'
	    else:
	        return 'bar'

	# with custom objects
	from gargoyle import gargoyle
	
	def my_method(user):
	    if gargoyle.is_active('my switch name', user):
	        return 'foo'
	    else:
	        return 'bar'

Condition Sets
==============

Gargoyle provides an easy way to hook in your own condition sets to allow additional filters. Simply place a ConditionSet class in ``myapp/gargoyle.py`` and it will automatically discover it::

	from gargoyle import conditions
	from django.contrib.sites.models import Site
	
	class SiteConditionSet(conditions.ModelConditionSet):
	    percent = conditions.Percent()
	    domain = conditions.String()
	
	gargoyle.register(SiteConditionSet(Site))

And now you can pass it into is_active::

	gargoyle.is_active('my switch name', Site.objects.get_current())<commit_msg>Update docs for custom condition sets<commit_after>Gargoyle
--------

Gargoyle is a platform built on top of Django which allows you to switch functionality of your application on and off based on conditions.

Screenshot
=========

.. image:: http://dl.dropbox.com/u/116385/Screenshots/-egenorlfjki.png

Installation
============

Install it with pip (or easy_install)::

	pip install gargoyle

Config
======

If you dont have `Nexus <https://github.com/dcramer/nexus>`_ already enabled, you will need to do that first.

(Nexus is a replacement for your Django admin frontend, that works with django.contrib.admin)

Now you just need to add Gargoyle to your ``INSTALLED_APPS``::

	INSTALLED_APPS = (
	    ...
	    'gargoyle',
	)

Usage
=====

Gargoyle is typically used in two fashions. The first and simplest, is as a decorator. The decorator will automatically integrate with filters registered to the ``User`` model, as well as IP address::

	from gargoyle.decorators import switch_is_active
	
	@switch_is_active('my switch name')
	def my_view(request):
	    return 'foo'

The second use is with the ``is_active`` method. This allows you to perform validation on your own custom objects::

	from gargoyle import gargoyle
	
	def my_function(request):
	    if gargoyle.is_active('my switch name', request):
	        return 'foo'
	    else:
	        return 'bar'

	# with custom objects
	from gargoyle import gargoyle
	
	def my_method(user):
	    if gargoyle.is_active('my switch name', user):
	        return 'foo'
	    else:
	        return 'bar'

Condition Sets
==============

Gargoyle provides an easy way to hook in your own condition sets to allow additional filters. Simply place a ConditionSet class in ``myapp/gargoyle.py`` and it will automatically discover it::

	from __future__ import absolute_import
	import gargoyle
	from gargoyle import conditions
	from django.contrib.sites.models import Site
	
	class SiteConditionSet(conditions.ModelConditionSet):
	    percent = conditions.Percent()
	    domain = conditions.String()
	
	gargoyle.register(SiteConditionSet(Site))

And now you can pass it into is_active::

	gargoyle.is_active('my switch name', Site.objects.get_current())
{'fraction_non_alphanumeric': 0.09718670076726342, 'fraction_numerical': 0.0027900488258544524, 'mean_word_length': 3.9448275862068964, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '699314', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1209, 'n_words': 480}