[astute,naily] Created module-level config class.

It was common in Astute & Naily: the same singleton of SymbolTable
This commit is contained in:
Mike Scherbakov 2013-01-30 17:35:09 +04:00
parent 8761cd3f3b
commit 6075ede1f1
2 changed files with 22 additions and 10 deletions

View File

@ -1,10 +1,6 @@
require 'symboltable'
require 'singleton'
class SymbolTable
include Singleton
end
module Astute
class ConfigError < StandardError; end
class UnknownOptionError < ConfigError
@ -16,6 +12,15 @@ module Astute
end
end
class MyConfig
include Singleton
attr_reader :configtable
def initialize
@configtable = SymbolTable.new
end
end
class ParseError < ConfigError
attr_reader :line
@ -26,7 +31,7 @@ module Astute
end
def self.config
config = SymbolTable.instance
config = MyConfig.instance.configtable
config.update(default_config) if config.empty?
return config
end

View File

@ -1,10 +1,6 @@
require 'symboltable'
require 'singleton'
class SymbolTable
include Singleton
end
module Naily
class ConfigError < StandardError; end
class UnknownOptionError < ConfigError
@ -16,6 +12,17 @@ module Naily
end
end
class MyConfig
include Singleton
attr_reader :configtable
def initialize
# We need new instance of SymbolTable. If we use singleton for SymbolTable,
# the same instance will be used in Astute.
@configtable = SymbolTable.new
end
end
class ParseError < ConfigError
attr_reader :line
@ -26,7 +33,7 @@ module Naily
end
def self.config
config = SymbolTable.instance
config = MyConfig.instance.configtable
config.update(default_config) if config.empty?
return config
end