Module: Feature
- Defined in:
- lib/feature/config.rb,
lib/feature.rb,
lib/feature/feature.rb,
lib/feature/version.rb,
lib/feature/dashboard.rb,
lib/feature/dashboard/helpers.rb
Overview
Class for the Feature configuration DSL. Methods defined here are available within the block passed to Feature.configure
Defined Under Namespace
Modules: DashboardHelpers Classes: Config, Dashboard, Feature, RedisBackend
Constant Summary collapse
- VERSION =
'0.1.0'.freeze
Class Method Summary collapse
-
.add_to_group(name, value) ⇒ Object
Ads a value to be part of a group.
- .backend ⇒ Object
-
.check_feature_defined(feature_name) ⇒ Object
Check that the given feature has been defined, raising an exception if not.
-
.configure(&block) ⇒ Object
Pass a block to configure, calling ‘feature’ for each feature you want to define.
- .features ⇒ Object
-
.get_group_members(group) ⇒ Object
Return an array of group member IDs.
-
.remove_from_group(name, value) ⇒ Object
Removes a value from a group.
Class Method Details
.add_to_group(name, value) ⇒ Object
Ads a value to be part of a group. This is useful at runtime to avoid having to restart the application just to enable / disable a feature for a given user.
Pass an instance of String that the backend will store
Note that groups are overriden at application restart so make sure to edit your config if you want the changes to be permanent.
15 16 17 |
# File 'lib/feature.rb', line 15 def self.add_to_group(name, value) backend.add_to_group(name, value) end |
.backend ⇒ Object
62 63 64 65 |
# File 'lib/feature.rb', line 62 def self.backend raise "No backend specified" if @backend.nil? @backend end |
.check_feature_defined(feature_name) ⇒ Object
Check that the given feature has been defined, raising an exception if not.
56 57 58 59 60 |
# File 'lib/feature.rb', line 56 def self.check_feature_defined(feature_name) unless @features.include?(feature_name) raise "Feature '#{feature_name}' is not defined" end end |
.configure(&block) ⇒ Object
Pass a block to configure, calling ‘feature’ for each feature you want to define.
Pass an instance of a backend (e.g. RedisBackend to backend)
Examples
Feature.configure do
backend Feature::RedisBackend($redis)
feature :postcode_lookup, default: :off
end
48 49 50 51 52 53 |
# File 'lib/feature.rb', line 48 def self.configure(&block) config = Config.new(block) @features ||= {} @features.merge!(config.features) @backend = config.backend_obj unless config.backend_obj.nil? end |
.features ⇒ Object
67 68 69 |
# File 'lib/feature.rb', line 67 def self.features @features end |
.get_group_members(group) ⇒ Object
Return an array of group member IDs
32 33 34 |
# File 'lib/feature.rb', line 32 def self.get_group_members(group) backend.get_group_members(group) end |
.remove_from_group(name, value) ⇒ Object
Removes a value from a group. This is useful at runtime to avoid having to restart the application just to enable / disable a feature for a given user.
Pass an instance of String that the backend will delete from the group
Note that groups are overriden at application restart so make sure to edit your config if you want the changes to be permanent.
27 28 29 |
# File 'lib/feature.rb', line 27 def self.remove_from_group(name, value) backend.remove_from_group(name, value) end |