Skip to content

Commit

Permalink
Extract Nanoc::Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Jul 9, 2016
1 parent d0c48dc commit 84dab0a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 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)

def self.enabled?(name)
env_name = "NANOC_FEAT_#{name.upcase}"
TRUES.include?(ENV.fetch(env_name, 'f').downcase)
end
end
end
3 changes: 1 addition & 2 deletions lib/nanoc/cli/commands/compile.rb
Expand Up @@ -356,8 +356,7 @@ class StackProfProfiler < Listener

# @see Listener#enable_for?
def self.enable_for?(_command_runner)
# TODO: Extract
ENV.fetch('NANOC_FEAT_PROFILER', 'false') == 'y'
Nanoc::Feature.enabled?('PROFILER')
end

# @see Listener#start
Expand Down
25 changes: 25 additions & 0 deletions spec/nanoc/base/feature_spec.rb
@@ -0,0 +1,25 @@
describe Nanoc::Feature do
describe '.enabled?' do
subject { described_class.enabled?(feature_name) }

let(:feature_name) { 'magic' }

context 'disabled' do
%w(0 n N no No NO false False fAlSe FALSE donkey).each do |val|
context "set to #{val}" do
before { ENV['NANOC_FEAT_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_FEAT_MAGIC'] = val }
it { is_expected.to be }
end
end
end
end
end

0 comments on commit 84dab0a

Please sign in to comment.