Module: Nanoc::Core::Feature
- Defined in:
- lib/nanoc/core/feature.rb
Overview
Class Method Summary collapse
-
.all_outdated ⇒ Enumerable<String>
Names of features that still exist, but should not be considered as experimental in the current version of Nanoc.
-
.define(name, version:) ⇒ void
Defines a new feature with the given name, experimental in the given version.
- .enable(feature_name) ⇒ Object private
-
.enabled?(feature_name) ⇒ Boolean
Whether or not the feature with the given name is enabled.
- .enabled_features ⇒ Object private
- .repo ⇒ Object private
- .reset_caches ⇒ Object private
-
.undefine(name) ⇒ void
Undefines the feature with the given name.
Class Method Details
.all_outdated ⇒ Enumerable<String>
Returns Names of features that still exist, but should not be considered as experimental in the current version of Nanoc.
84 85 86 87 88 89 |
# File 'lib/nanoc/core/feature.rb', line 84 def self.all_outdated repo.keys.reject do |name| version = repo[name] Nanoc::Core::VERSION.start_with?(version) end end |
.define(name, version:) ⇒ void
This method returns an undefined value.
Defines a new feature with the given name, experimental in the given version. The feature will be made available as a constant with the same name, in uppercase, on the Nanoc::Core::Feature module.
25 26 27 28 |
# File 'lib/nanoc/core/feature.rb', line 25 def self.define(name, version:) repo[name] = version const_set(name.upcase, name) end |
.enable(feature_name) ⇒ 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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/nanoc/core/feature.rb', line 51 def self.enable(feature_name) raise ArgumentError, 'no block given' unless block_given? if enabled?(feature_name) yield else begin enabled_features << feature_name yield ensure enabled_features.delete(feature_name) end end end |
.enabled?(feature_name) ⇒ Boolean
Returns Whether or not the feature with the given name is enabled.
45 46 47 48 |
# File 'lib/nanoc/core/feature.rb', line 45 def self.enabled?(feature_name) enabled_features.include?(feature_name) || enabled_features.include?('all') end |
.enabled_features ⇒ 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.
72 73 74 |
# File 'lib/nanoc/core/feature.rb', line 72 def self.enabled_features @_enabled_features ||= Set.new(ENV.fetch('NANOC_FEATURES', '').split(',')) end |
.repo ⇒ 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.
77 78 79 |
# File 'lib/nanoc/core/feature.rb', line 77 def self.repo @_repo ||= {} end |
.reset_caches ⇒ 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.
67 68 69 |
# File 'lib/nanoc/core/feature.rb', line 67 def self.reset_caches @_enabled_features = nil end |
.undefine(name) ⇒ void
This method returns an undefined value.
Undefines the feature with the given name. For testing purposes only.
37 38 39 40 |
# File 'lib/nanoc/core/feature.rb', line 37 def self.undefine(name) repo.delete(name) remove_const(name.upcase) end |