Module: Pageflow::GlobalConfigApi

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

Overview

rubocop:todo Style/Documentation

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:



67
68
69
70
# File 'lib/pageflow/global_config_api.rb', line 67

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



80
81
82
83
# File 'lib/pageflow/global_config_api.rb', line 80

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

def config(options = {})
  unless @config
    return Configuration.new if options[:ignore_not_configured]

    raise('Pageflow has not been configured yet')

  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



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pageflow/global_config_api.rb', line 45

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:



34
35
36
37
# File 'lib/pageflow/global_config_api.rb', line 34

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.



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

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.

Returns:

  • (Boolean)

Since:

  • 0.9



26
27
28
# File 'lib/pageflow/global_config_api.rb', line 26

def configured?
  !!@config
end

#finalize!Object

Call from the pageflow initializer to indicate that the coniguration is now complete.



87
88
89
# File 'lib/pageflow/global_config_api.rb', line 87

def finalize!
  @finalized = true
end