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.
- #logger ⇒ Shamu::Logger
-
#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
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, policy_class, #service_policy_delegation?
Methods inherited from Services::Service
#cache_for, #cached_lookup, #entity_list, #entity_lookup_list, #find_by_lookup, #lazy_association, #lookup_association
Constructor Details
#initialize(config_path) ⇒ FeaturesService
46 47 48 49 50 |
# File 'lib/shamu/features/features_service.rb', line 46 def initialize( config_path = nil ) @config_path = config_path || self.class.default_config_path super() 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 |
#logger ⇒ Shamu::Logger
38 |
# File 'lib/shamu/features/features_service.rb', line 38 attr_dependency :logger, Shamu::Logger |
#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.
157 158 159 160 161 162 163 |
# File 'lib/shamu/features/features_service.rb', line 157 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
167 168 169 |
# File 'lib/shamu/features/features_service.rb', line 167 def default_config_path=( path ) # rubocop:disable Style/TrivialAccessors @default_config_path = path end |
Instance Method Details
#enabled?(name) ⇒ Boolean
Indicates if the feature is enabled for the current request/session.
56 57 58 59 60 61 62 63 64 |
# File 'lib/shamu/features/features_service.rb', line 56 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.
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/shamu/features/features_service.rb', line 69 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 |