Module: Configliere::ConfigBlock

Defined in:
lib/configliere/config_block.rb

Overview

ConfigBlock lets you use pure ruby to change and define settings. Call +#finally+ with a block of code to be run after all other settings are in place.

Settings.finally{|c| c.your_mom[:college] = 'went' unless (! c.mom_jokes_allowed) }

Instance Method Summary collapse

Instance Method Details

#finally(&block) ⇒ Object

Define a block of code to run after all other settings are in place.

Examples:

Settings.finally do |c|
  c.dest_time = (Time.now + 60) if c.username == 'einstein'
  # you can use hash syntax too
  c[:dest_time] = (Time.now + 60) if c[:username] == 'einstein'
end
# ...
# after rest of setup:
Settings.resolve!

Parameters:

  • &block

    each +finally+ block is called once, in the order it was defined, when the resolve! method is invoked. +config_block+ resolution is guaranteed to run last in the resolve chain, right before validation.



27
28
29
# File 'lib/configliere/config_block.rb', line 27

def finally &block
  self.final_blocks << block if block
end

#resolve!Object

Processing to reconcile all options

The resolve! for config_block is made to run last of all in the +resolve!+ chain, and runs each +finally+ block in the order it was defined.



35
36
37
38
39
# File 'lib/configliere/config_block.rb', line 35

def resolve!
  super
  resolve_finally_blocks!
  self
end