Class: M2Config::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/m2config.rb

Constant Summary collapse

DEFAULT_CONFIG =
"config.sqlite"
SCHEMA =
File.read("#{File.dirname __FILE__}/m2config/schema.sql")
@@foundTables =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fileName = DEFAULT_CONFIG, options = {}) ⇒ Config

Returns a new instance of Config.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/m2config.rb', line 26

def initialize(fileName = DEFAULT_CONFIG, options={})
  @fileName = fileName
  creating = ! (File.exists? @fileName)
  @db = Sequel.connect "sqlite://#{@fileName}"
  
  @db.run SCHEMA if creating
 
  Sequel::Model.db = @db
  
  require "m2config/server"
  require "m2config/host"
  require "m2config/dir"
  require "m2config/route"
  require "m2config/proxy"
  require "m2config/handler"
  require "m2config/setting"
  require "m2config/mimetype"

  M2Config::MimeType.populate_table(nil,options[:ignoreDoubles]) if creating
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



11
12
13
# File 'lib/m2config.rb', line 11

def db
  @db
end

Class Method Details

.tablesObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/m2config.rb', line 15

def self.tables
  return @@foundTables unless @@foundTables.empty?
  SCHEMA.split("\n").each do 
    |l|
    if l =~ /CREATE TABLE (\w+)/
      @@foundTables.push $1
    end
  end
  @@foundTables
end

Instance Method Details

#[]=(k, v) ⇒ Object



51
52
53
# File 'lib/m2config.rb', line 51

def []=( k, v )
  Setting.new k, v
end

#add_server(settings = {}) ⇒ Object



47
48
49
# File 'lib/m2config.rb', line 47

def add_server( settings = {} )
  srv = Server.new settings
end