Sha256: dc190dbd9d41a3b7652d280122ab751a2022d62436614c1cadeb69eef7bd735a
Contents?: true
Size: 1.64 KB
Versions: 2
Compression:
Stored size: 1.64 KB
Contents
Configliere.use :define module Configliere # # 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) } # module ConfigBlock # # @param &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. # # @example # 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! # def finally &block self.final_blocks << block end # 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. def resolve! super resolve_finally_blocks! self end protected # Config blocks to be executed at end of resolution (just before validation) attr_accessor :final_blocks def final_blocks @final_blocks ||= [] end # call each +finally+ config block in the order it was defined def resolve_finally_blocks! final_blocks.each do |block| block.call(self) end end end Param.class_eval do include Configliere::ConfigBlock end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
configliere-0.0.5 | lib/configliere/config_block.rb |
configliere-0.0.4 | lib/configliere/config_block.rb |