Skip to content

Commit

Permalink
Merge pull request #681 from dudo/Add-env-vars-to-railtie
Browse files Browse the repository at this point in the history
Add ENV vars to railtie
  • Loading branch information
jnunemaker committed Dec 1, 2022
2 parents 6d00b0a + 6396119 commit 5e7d9bb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/flipper/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module Flipper
class Railtie < Rails::Railtie
config.before_configuration do
config.flipper = ActiveSupport::OrderedOptions.new.update(
env_key: "flipper",
memoize: true,
preload: true,
instrumenter: ActiveSupport::Notifications,
log: true
env_key: ENV.fetch('FLIPPER_ENV_KEY', 'flipper'),
memoize: ENV.fetch('FLIPPER_MEMOIZE', 'true').casecmp('true').zero?,
preload: ENV.fetch('FLIPPER_PRELOAD', 'true').casecmp('true').zero?,
instrumenter: ENV.fetch('FLIPPER_INSTRUMENTER', 'ActiveSupport::Notifications').constantize,
log: ENV.fetch('FLIPPER_LOG', 'true').casecmp('true').zero?
)
end

Expand Down
36 changes: 36 additions & 0 deletions spec/flipper/railtie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,42 @@
subject { application.initialize! }

describe 'initializers' do
it 'can set env_key from ENV' do
ENV['FLIPPER_ENV_KEY'] = 'flopper'

subject
expect(config.env_key).to eq('flopper')
end

it 'can set memoize from ENV' do
ENV['FLIPPER_MEMOIZE'] = 'false'

subject
expect(config.memoize).to eq(false)
end

it 'can set preload from ENV' do
ENV['FLIPPER_PRELOAD'] = 'false'

subject
expect(config.preload).to eq(false)
end

it 'can set instrumenter from ENV' do
stub_const('My::Cool::Instrumenter', Class.new)
ENV['FLIPPER_INSTRUMENTER'] = 'My::Cool::Instrumenter'

subject
expect(config.instrumenter).to eq(My::Cool::Instrumenter)
end

it 'can set log from ENV' do
ENV['FLIPPER_LOG'] = 'false'

subject
expect(config.log).to eq(false)
end

it 'sets defaults' do
subject # initialize
expect(config.env_key).to eq("flipper")
Expand Down

0 comments on commit 5e7d9bb

Please sign in to comment.