Sha256: 760fb969abf05c6da577380e88f3816c55bc912b381081d48ddd88142c26b09b

Contents?: true

Size: 762 Bytes

Versions: 5

Compression:

Stored size: 762 Bytes

Contents

module Configatron
  module Helpers
    
    # Checks whether or not configuration parameter exists.
    def exists?(name)
      self.respond_to?(name)
    end
    
    def handle_missing_parameter(param) # :nodoc:
      if configatron.nil_for_missing
        return nil
      else
        raise NoMethodError.new(param.to_s)
      end
    end
    
    # Retrieves the specified config parameter. An optional second
    # parameter can be passed that will be returned if the config
    # parameter doesn't exist.
    def retrieve(name, default_value = ArgumentError)
      return self.send(name) if exists?(name)
      return default_value unless default_value == ArgumentError
      handle_missing_parameter(name)
    end
    
  end # Helpers
end # Configatron 

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
configatron-1.1.0 lib/helpers.rb
configatron-1.0.1 lib/helpers.rb
configatron-1.2.1 lib/configatron/helpers.rb
configatron-1.2.0 lib/configatron/helpers.rb
configatron-1.2.2 lib/configatron/helpers.rb