Class: Pageflow::Features
- Inherits:
-
Object
- Object
- Pageflow::Features
- Includes:
- Enumerable
- Defined in:
- lib/pageflow/features.rb
Overview
A registry of [Feature} objects.
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #enable(names, config) ⇒ Object private
- #enable_all(config) ⇒ Object private
-
#enabled?(name) ⇒ Boolean
Check if a feature has been enabled.
-
#initialize ⇒ Features
constructor
private
A new instance of Features.
-
#register(feature, &block) ⇒ Object
Register a feature that can be enabled for accounts of entries.
Constructor Details
#initialize ⇒ Features
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Features.
9 10 11 12 |
# File 'lib/pageflow/features.rb', line 9 def initialize @features = {} @enabled_features = [] end |
Instance Method Details
#each(&block) ⇒ Object
64 65 66 |
# File 'lib/pageflow/features.rb', line 64 def each(&block) @features.values.each(&block) end |
#enable(names, config) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 50 51 52 53 54 55 56 57 |
# File 'lib/pageflow/features.rb', line 49 def enable(names, config) @enabled_features = names names.each do |name| raise(ArgumentError, "Cannot enable unknown feature #{name}.") unless @features.key?(name) @features[name].enable(config) end end |
#enable_all(config) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 |
# File 'lib/pageflow/features.rb', line 60 def enable_all(config) enable(@features.keys, config) end |
#enabled?(name) ⇒ Boolean
Check if a feature has been enabled.
44 45 46 |
# File 'lib/pageflow/features.rb', line 44 def enabled?(name) @enabled_features.include?(name) end |
#register(feature) ⇒ Object #register(feature) {|config| ... } ⇒ Object #register(feature) ⇒ Object
Register a feature that can be enabled for accounts of entries. If the first parameter is a string, a block can be passed to provide the enable method. If only a string is passed, enabling the feature is no-op.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pageflow/features.rb', line 29 def register(feature, &block) if feature.is_a?(String) return register(Feature.new(feature, &block)) end if @features.key?(feature.name) raise(ArgumentError, "Feature #{feature.name} is already registered.") end @features[feature.name] = feature end |