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.
68 69 70 71 |
# File 'lib/pageflow/global_config_api.rb', line 68 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.
81 82 83 84 |
# File 'lib/pageflow/global_config_api.rb', line 81 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 51 52 53 54 55 56 57 58 |
# File 'lib/pageflow/global_config_api.rb', line 46 def config_for(target) config = build_config( target.respond_to?(:entry_type) && target.entry_type.name ) do |c| c.enable_features(target.enabled_feature_names(c)) end if target.respond_to?(:entry_type) config = Configuration::ConfigView.new(config, target.entry_type) end config 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.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/pageflow/global_config_api.rb', line 93 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 @config.lint! 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.
88 89 90 |
# File 'lib/pageflow/global_config_api.rb', line 88 def finalize! @finalized = true end |