Sha256: b92d14703cdf7b6aa77f1e053c84c4bc9a55c6393f238f5f1e9a58ec4ab6dd0d

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

Configliere.use :define
module Configliere
  module ConfigBlock
    # Config blocks to be executed at end of resolution (just before validation)
    attr_accessor :final_blocks
    def final_blocks
      @final_blocks ||= []
    end

    # @param param the setting to describe. Either a simple symbol or a dotted param string.
    # @param definitions the defineables to set (:description, :type, :encrypted, etc.)
    #
    # @example
    #   Settings.define :dest_time, :type => Date, :description => 'Arrival time. If only a date is given, the current time of day on that date is assumed.'
    #   Settings.define 'delorean.power_source', :description => 'Delorean subsytem supplying power to the Flux Capacitor.'
    #   Settings.define :password, :required => true, :obscure => true
    #
    def finally &block
      self.final_blocks << block
    end

    # calls superclass resolution
    def resolve!
      begin ; super() ; rescue NoMethodError ; nil ; end
      resolve_finally_blocks!
      self
    end

  protected
    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

1 entries across 1 versions & 1 rubygems

Version Path
configliere-0.0.2 lib/configliere/config_block.rb