Skip to content

Commit

Permalink
Add support for feature flags
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Jul 10, 2016
1 parent b22c2d8 commit 1bb064d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/nanoc/base.rb
Expand Up @@ -25,6 +25,7 @@ module Nanoc::Int
require_relative 'base/contracts_support'

require_relative 'base/entities'
require_relative 'base/feature'
require_relative 'base/repos'
require_relative 'base/services'
require_relative 'base/views'
11 changes: 11 additions & 0 deletions lib/nanoc/base/feature.rb
@@ -0,0 +1,11 @@
module Nanoc
# @api private
module Feature
TRUES = %w(y yes 1 t true).freeze

def self.enabled?(name)
env_name = "NANOC_FEATURE_#{name.upcase}"
TRUES.include?(ENV.fetch(env_name, 'f').downcase)
end
end
end
29 changes: 29 additions & 0 deletions spec/nanoc/base/feature_spec.rb
@@ -0,0 +1,29 @@
describe Nanoc::Feature do
describe '.enabled?' do
subject { described_class.enabled?(feature_name) }

let(:feature_name) { 'magic' }

context 'disabled' do
context 'not set' do
it { is_expected.not_to be }
end

%w(0 n N no No NO false False fAlSe FALSE donkey).each do |val|
context "set to #{val}" do
before { ENV['NANOC_FEATURE_MAGIC'] = val }
it { is_expected.not_to be }
end
end
end

context 'enabled' do
%w(1 y Y yes yEs YES t True tRuE TRUE).each do |val|
context "set to #{val}" do
before { ENV['NANOC_FEATURE_MAGIC'] = val }
it { is_expected.to be }
end
end
end
end
end

0 comments on commit 1bb064d

Please sign in to comment.