Module: Pageflow::GlobalConfigApi

Included in:
Pageflow
Defined in:
lib/pageflow/global_config_api.rb

Instance Method Summary collapse

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.

Yield Parameters:



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.

Yield Parameters:

Since:

  • 0.9



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.

Returns:



12
13
14
15
16
17
18
19
20
21
# File 'lib/pageflow/global_config_api.rb', line 12

def config(options = {})
  unless @config
    if options[: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.

Parameters:

  • target (#enabled_feature_names)

Returns:

Since:

  • 0.9



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.

Yield Parameters:



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.



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/pageflow/global_config_api.rb', line 95

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.

Returns:

  • (Boolean)

Since:

  • 0.9



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
91
92
# File 'lib/pageflow/global_config_api.rb', line 88

def finalize!
  @finalized = true
  configure!
  @config.lint!
end