Module: Toggly::Rails::ViewHelpers
- Defined in:
- lib/toggly/rails/view_helpers.rb
Overview
View helpers for feature flags in Rails views.
These helpers are automatically included in ActionView when using the Railtie.
Instance Method Summary collapse
-
#feature_disabled?(feature_key, context: nil) ⇒ Boolean
Check if a feature is disabled.
-
#feature_enabled?(feature_key, context: nil) ⇒ Boolean
Check if a feature is enabled.
-
#feature_switch(feature_key, enabled: nil, disabled: nil, context: nil) ⇒ String
Render enabled or disabled content based on feature state.
-
#when_feature_disabled(feature_key, context: nil) { ... } ⇒ String?
Render content only if feature is disabled.
-
#when_feature_enabled(feature_key, context: nil) { ... } ⇒ String?
Render content only if feature is enabled.
Instance Method Details
#feature_disabled?(feature_key, context: nil) ⇒ Boolean
Check if a feature is disabled
29 30 31 |
# File 'lib/toggly/rails/view_helpers.rb', line 29 def feature_disabled?(feature_key, context: nil) !feature_enabled?(feature_key, context: context) end |
#feature_enabled?(feature_key, context: nil) ⇒ Boolean
Check if a feature is enabled
15 16 17 18 19 20 21 22 |
# File 'lib/toggly/rails/view_helpers.rb', line 15 def feature_enabled?(feature_key, context: nil) if controller.respond_to?(:feature_enabled?, true) controller.send(:feature_enabled?, feature_key, context: context) else ctx = context || view_toggly_context Toggly.enabled?(feature_key, context: ctx) end end |
#feature_switch(feature_key, enabled: nil, disabled: nil, context: nil) ⇒ String
Render enabled or disabled content based on feature state
64 65 66 67 68 69 70 |
# File 'lib/toggly/rails/view_helpers.rb', line 64 def feature_switch(feature_key, enabled: nil, disabled: nil, context: nil) if feature_enabled?(feature_key, context: context) enabled else disabled end end |
#when_feature_disabled(feature_key, context: nil) { ... } ⇒ String?
Render content only if feature is disabled
51 52 53 54 55 |
# File 'lib/toggly/rails/view_helpers.rb', line 51 def when_feature_disabled(feature_key, context: nil, &block) return if feature_enabled?(feature_key, context: context) capture(&block) if block_given? end |
#when_feature_enabled(feature_key, context: nil) { ... } ⇒ String?
Render content only if feature is enabled
39 40 41 42 43 |
# File 'lib/toggly/rails/view_helpers.rb', line 39 def when_feature_enabled(feature_key, context: nil, &block) return unless feature_enabled?(feature_key, context: context) capture(&block) if block_given? end |