Module: Pageflow::GlobalConfigApi
- Included in:
- Pageflow
- Defined in:
- lib/pageflow/global_config_api.rb
Instance Method Summary collapse
-
#after_configure {|config| ... } ⇒ Object
Register a block which shall be called after any configuration object has been built.
-
#after_global_configure {|config| ... } ⇒ Object
Register a block which shall be called after the global configuration has been built.
-
#config(options = {}) ⇒ Configuration
The global configuration.
-
#config_for(target) ⇒ Configuration
Build configuration object for which certain features have been enabled.
-
#configure {|config| ... } ⇒ Object
Register a block to be invoked each time a pageflow configuration is created.
- #configure! ⇒ Object private
-
#configured? ⇒ Boolean
Returns true if pageflow has already been configures.
-
#finalize! ⇒ Object
Call from the pageflow initializer to indicate that the coniguration is now complete.
Instance Method Details
#after_configure {|config| ... } ⇒ Object
Register a block which shall be called after any configuration object has been built. The passed configuration already includes any enabled features.
Use this hook to finalize configuration objects i.e. registering help topics for registered page types.
60 61 62 63 |
# File 'lib/pageflow/global_config_api.rb', line 60 def after_configure(&block) @after_configure_blocks ||= [] @after_configure_blocks << block end |
#after_global_configure {|config| ... } ⇒ Object
Register a block which shall be called after the global configuration has been built. All features are enabled in the passed configuration. For example, this hook can be used to perform actions for any page type that might be enabled at some point in the application.
73 74 75 76 |
# File 'lib/pageflow/global_config_api.rb', line 73 def after_global_configure(&block) @after_global_configure_blocks ||= [] @after_global_configure_blocks << block end |
#config(options = {}) ⇒ Configuration
The global configuration.
Note that all features have been activated for this configuration object.
Use #config_for to build a configuration object with only certain features enabled.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/pageflow/global_config_api.rb', line 12 def config( = {}) unless @config if [:ignore_not_configured] return Configuration.new else raise('Pageflow has not been configured yet') end end @config end |
#config_for(target) ⇒ Configuration
Build configuration object for which certain features have been enabled.
46 47 48 49 50 |
# File 'lib/pageflow/global_config_api.rb', line 46 def config_for(target) build_config do |config| config.enable_features(target.enabled_feature_names) end end |
#configure {|config| ... } ⇒ Object
Register a block to be invoked each time a pageflow configuration is created. The block is passed the config object.
35 36 37 38 |
# File 'lib/pageflow/global_config_api.rb', line 35 def configure(&block) @configure_blocks ||= [] @configure_blocks << block end |
#configure! ⇒ 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.
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/pageflow/global_config_api.rb', line 87 def configure! return unless @finalized @config = build_config do |config| config.enable_all_features end @after_global_configure_blocks ||= [] @after_global_configure_blocks.each do |block| block.call(@config) end end |
#configured? ⇒ Boolean
Returns true if pageflow has already been configures.
27 28 29 |
# File 'lib/pageflow/global_config_api.rb', line 27 def configured? !!@config end |
#finalize! ⇒ Object
Call from the pageflow initializer to indicate that the coniguration is now complete.
80 81 82 83 84 |
# File 'lib/pageflow/global_config_api.rb', line 80 def finalize! @finalized = true configure! @config.lint! end |