main
1# frozen_string_literal: true
2
3module Featurable
4 extend ActiveSupport::Concern
5
6 included do
7 helper_method :feature_enabled?
8 end
9
10 class_methods do
11 def require_feature(features, options = {})
12 before_action(options) do
13 missing_feature = Array(features).any? { |x| feature_disabled?(x) }
14 render plain: "Forbidden", status: :forbidden if missing_feature
15 end
16 end
17 end
18
19 def feature_enabled?(feature)
20 Current.user&.feature_enabled?(feature) || Flipper.enabled?(feature.to_sym)
21 end
22
23 def feature_disabled?(feature)
24 !feature_enabled?(feature)
25 end
26end