class SmoothChange::ClientFeatureToggler
Store client features requirements
Public Class Methods
from_http_header(http_header_value)
click to toggle source
Http header is expected to be a comma separated list like :
"feature1, !feature2, feature3"
Spaces between elements are ignored A leading “!” means the feature request is opt-out
# File lib/smooth_change/client_feature_toggler.rb, line 30 def self.from_http_header(http_header_value) values = http_header_value .split(",") .each_with_object({}) do |item, memo| feature_name = item.strip # NOTE: delete_prefix! returns nil if prefix is not found enabled = !feature_name.delete_prefix!("!") memo[feature_name] = enabled end new(values) end
new(values = {})
click to toggle source
# File lib/smooth_change/client_feature_toggler.rb, line 6 def initialize(values = {}) @values = values.transform_keys(&:to_sym) end
Public Instance Methods
enabled?(feature_name)
click to toggle source
# File lib/smooth_change/client_feature_toggler.rb, line 21 def enabled?(feature_name) feature = find_feature(feature_name) feature.enabled_with?(self) end
value_for(feature)
click to toggle source
if true : feature is wanted if false : feature is explicitly not wanted if nil : not specified
# File lib/smooth_change/client_feature_toggler.rb, line 17 def value_for(feature) values[feature.to_sym] end
values()
click to toggle source
# File lib/smooth_change/client_feature_toggler.rb, line 10 def values @values ||= {} end
Private Instance Methods
adapter()
click to toggle source
# File lib/smooth_change/client_feature_toggler.rb, line 45 def adapter SmoothChange.configuration.adapter end
find_feature(feature_name)
click to toggle source
@return [SmoothChange::Feature] @param [String] feature_name
# File lib/smooth_change/client_feature_toggler.rb, line 51 def find_feature(feature_name) adapter.get(feature_name) end