Module: FeatureGuard::Policy
- Defined in:
- lib/feature_guard/policy.rb
Instance Method Summary collapse
-
#initialize(current_user:, feature_setting:) ⇒ Object
feature_settingis used for declared feature methods that the policy does not override directly. -
#method_missing(method_name) ⇒ Object
A missing policy predicate falls back to the identically named persisted setting predicate.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
A missing policy predicate falls back to the identically named persisted setting predicate. Defined policy methods fully override that setting.
14 15 16 17 18 |
# File 'lib/feature_guard/policy.rb', line 14 def method_missing(method_name, ...) return super unless method_name.to_s.end_with?('?') persisted_feature_enabled?(method_name) end |
Instance Method Details
#initialize(current_user:, feature_setting:) ⇒ Object
feature_setting is used for declared feature methods that the policy
does not override directly.
7 8 9 10 |
# File 'lib/feature_guard/policy.rb', line 7 def initialize(current_user:, feature_setting:) @current_user = current_user @feature_setting = feature_setting end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
20 21 22 23 24 |
# File 'lib/feature_guard/policy.rb', line 20 def respond_to_missing?(method_name, include_private = false) return super unless method_name.to_s.end_with?('?') @feature_setting.respond_to?(method_name, include_private) || super end |