[astute,naily] Created module-level config class.
It was common in Astute & Naily: the same singleton of SymbolTable
This commit is contained in:
parent
8761cd3f3b
commit
6075ede1f1
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue