Module: FeatureGuard::Policy

Defined in:
lib/feature_guard/policy.rb

Instance Method Summary collapse

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

Returns:

  • (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