Git’s cheap branching and merging ability coupled with Git Flow makes software feature development process a lot easier. However product development is only 1 piece of the puzzle when it comes down to feature release. It’s almost certain that when we release a feature, there will be involvements from support/sales/marketing team. Feature code ready simply doesn’t mean release ready. Some may say, why not just keep the non-released feature code in the Git feature branch… I personally don’t like keeping feature branches long-lived and prefer quick merge-backs. This leads to the question, how can we decouple product development code release and product feature release.
Since knowing that the feature toggle requirement is all on UI side for now, I quickly rolled up my sleeves and hacked together a solution.
First create a features model and back it up with a DB table (yes, it’s the Rails way …). The only significant method is the class method
feature_map, which returns me a hash of active features.
Next up, create a plain Ruby class with a class method
get_map, which does a cache fetch on a given hash key.
Then, I created a couple of helper methods as such
Last, in my (HAML) view files, I can just wrap the feature related view code inside the
envisio_alternative helper methods like this
That’s it. The view files are still declaritive without if/else checks.
Of course, there’s an admin only control panel, where administrators can signin to and toggle on/off features without involvement from development team.