Class: Shamu::Features::FeaturesService
- Inherits:
-
Services::Service
- Object
- Services::Service
- Shamu::Features::FeaturesService
- Includes:
- Security::Support
- Defined in:
- lib/shamu/features/features_service.rb
Overview
...
Constant Summary collapse
- SESSION_KEY =
"shamu.toggles".freeze
Dependencies collapse
-
#env_store ⇒ Shamu::Features::EnvStore
Read-only access to Rack and host ENV toggle overrides.
-
#session_store ⇒ Shamu::Sessions::SessionStore
A persistent storage for a user session where the feature service can persist sticky feature toggles.
-
#toggle_codec ⇒ Shamu::Features::ToggleCodec
Used to pack and unpack sticky toggle overrides in a persistent user session.
Attributes included from Security::Support
#roles_service, #security_principal
Attributes inherited from Services::Service
Class Method Summary collapse
-
.default_config_path ⇒ String
Looks for a config/features.yml or features.yml in the current directory.
- .default_config_path=(path) ⇒ String
Instance Method Summary collapse
-
#enabled?(name) ⇒ Boolean
Indicates if the feature is enabled for the current request/session.
- #initialize(config_path) ⇒ FeaturesService constructor
-
#list(prefix = nil) ⇒ Hash
List all the known toggles with the given prefix.
Methods included from Security::Support
#authorize!, #delegate_policy_class, #permit?, #policy, #policy_class, #service_policy_delegation?
Methods inherited from Services::Service
#cache_for, #cached_lookup, #entity_list, #entity_lookup_list, #error, #find_by_lookup, #lazy_association, #lookup_association, #result
Constructor Details
#initialize(config_path) ⇒ FeaturesService
42 43 44 |
# File 'lib/shamu/features/features_service.rb', line 42 initialize do |config_path = nil, **| @config_path = config_path || self.class.default_config_path end |
Instance Attribute Details
#env_store ⇒ Shamu::Features::EnvStore
Read-only access to Rack and host ENV toggle overrides.
34 |
# File 'lib/shamu/features/features_service.rb', line 34 attr_dependency :env_store, Shamu::Features::EnvStore |
#session_store ⇒ Shamu::Sessions::SessionStore
A persistent storage for a user session where the feature service can persist sticky feature toggles.
21 |
# File 'lib/shamu/features/features_service.rb', line 21 attr_dependency :session_store, Shamu::Sessions::SessionStore |
#toggle_codec ⇒ Shamu::Features::ToggleCodec
Used to pack and unpack sticky toggle overrides in a persistent user session.
28 |
# File 'lib/shamu/features/features_service.rb', line 28 attr_dependency :toggle_codec, Shamu::Features::ToggleCodec |
Class Method Details
.default_config_path ⇒ String
Looks for a config/features.yml or features.yml in the current directory. Use #ddefault_config_path= to manually set the default config file.
151 152 153 154 155 156 157 |
# File 'lib/shamu/features/features_service.rb', line 151 def default_config_path @default_config_path ||= begin path = File.( "config/features.yml" ) path = File.( "features.yml" ) unless File.exist?( path ) path end end |
.default_config_path=(path) ⇒ String
161 162 163 |
# File 'lib/shamu/features/features_service.rb', line 161 def default_config_path=( path ) @default_config_path = path end |
Instance Method Details
#enabled?(name) ⇒ Boolean
Indicates if the feature is enabled for the current request/session.
50 51 52 53 54 55 56 57 58 |
# File 'lib/shamu/features/features_service.rb', line 50 def enabled?( name ) context = build_context if toggle = toggles[name] resolve_known( toggle, context ) else resolve_unknown( name ) end end |
#list(prefix = nil) ⇒ Hash
List all the known toggles with the given prefix.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/shamu/features/features_service.rb', line 63 def list( prefix = nil ) if prefix.present? toggles.each_with_object({}) do |(name, toggle), result| next unless name.start_with?( prefix ) result[name] = toggle end else toggles.dup end end |