class TinyConfig

Constants

VERSION

Public Class Methods

clear!() click to toggle source
# File lib/tiny_config.rb, line 32
def self.clear!
  constants.each { |c| remove_const(c) unless c =~ /Error$/ }
end
method_missing(namespace) click to toggle source
# File lib/tiny_config.rb, line 27
def self.method_missing namespace
  raise UndefinedNamespaceError, namespace unless self.constants.include? namespace.capitalize
  const_get(namespace.capitalize).instance
end
register(namespace, config_keys) click to toggle source
# File lib/tiny_config.rb, line 5
def self.register(namespace, config_keys)
  const_set namespace.capitalize, Class.new {
    include ::Singleton

    config_keys = [config_keys] unless config_keys.instance_of?(Array)

    config_keys.each do |config_key|
      attr_writer config_key

      define_method config_key do
        v = instance_variable_get("@#{config_key}")
        v.nil? ? raise(TinyConfig::ConfigKeyNillError, message(config_key)) : v
      end
    end

    def message config_key
      namespace = self.class.to_s.split('::').last.downcase
      "#{namespace} #{config_key} is requried."
    end
  }
end

Public Instance Methods

message(config_key) click to toggle source
# File lib/tiny_config.rb, line 20
def message config_key
  namespace = self.class.to_s.split('::').last.downcase
  "#{namespace} #{config_key} is requried."
end