Module: FtGem::Controllers::Helpers

Extended by:
ActiveSupport::Concern
Defined in:
lib/ft_gem/controllers/helpers.rb

Constant Summary collapse

'mnft'.freeze

Instance Method Summary collapse

Instance Method Details

#api_feature_toggle_status(name:) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/ft_gem/controllers/helpers.rb', line 18

def api_feature_toggle_status(name:)
  toggle = FtShared.fetch(name: name)
  return false if toggle.nil?
  toggle['feature_toggle']['toggle_percentage'].to_i == 100
rescue StandardError => e
  Rails.logger.error "FtGem::api_feature_toggle_status error #{e.backtrace}"
  false
end

#feature_toggle_status(name:) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/ft_gem/controllers/helpers.rb', line 7

def feature_toggle_status(name:)
  cookies[TOGGLE_COOKIE_NAME] = rand(0..100) if cookies[TOGGLE_COOKIE_NAME].nil? || cookies[TOGGLE_COOKIE_NAME].to_i.zero?
  data = FtShared.fetch(name: name)
  toggle_percentage = data['feature_toggle']['toggle_percentage']
  client_percentage = cookies[TOGGLE_COOKIE_NAME]
  client_percentage.to_i <= toggle_percentage.to_i
rescue StandardError => e
  Rails.logger.error "FtGem::feature_toggle_status error #{e.backtrace}"
  false
end