m2config 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/m2config/host.rb +4 -4
- data/lib/m2config/proxy.rb +0 -1
- data/lib/m2config/route.rb +15 -1
- data/lib/m2config/server.rb +7 -7
- data/lib/m2config/version.rb +1 -1
- data/sample/full.rb +1 -1
- data/spec/host_spec.rb +13 -1
- data/spec/route_spec.rb +27 -2
- data/spec/server_spec.rb +14 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30d8a9fa3eccc1534a6cbff481a910190e163332
|
4
|
+
data.tar.gz: 31d5f71abafec20f678f4fb290e631b231ca475e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c08369ceb3433048c01f1a49108711dcda9330516ec90753f7937072b404d020e39390dd9e507f87cf0eb5af26da109f6d2b5792ba74d20fb4af897777a6a797
|
7
|
+
data.tar.gz: 3dd55d203a07f423ed59bde04b17929618559d32a9cb204303394b85452eb4b50c13be6f678115caaba695f7689308fcbf979710a1188fdf1694d85e976dd78d
|
data/lib/m2config/host.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module M2Config
|
2
2
|
class Host < Sequel::Model(:host)
|
3
|
-
|
3
|
+
one_to_many :routes
|
4
4
|
|
5
5
|
def initialize( fields )
|
6
6
|
s = resolveServer fields
|
@@ -10,8 +10,9 @@ module M2Config
|
|
10
10
|
save
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
13
|
+
def check_routes
|
14
|
+
paths = routes.map { |route| route[:path] }
|
15
|
+
paths.uniq.size == paths.size
|
15
16
|
end
|
16
17
|
|
17
18
|
private
|
@@ -29,6 +30,5 @@ module M2Config
|
|
29
30
|
s
|
30
31
|
end
|
31
32
|
|
32
|
-
|
33
33
|
end
|
34
34
|
end
|
data/lib/m2config/proxy.rb
CHANGED
data/lib/m2config/route.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module M2Config
|
2
2
|
class Route < Sequel::Model(:route)
|
3
|
-
|
3
|
+
many_to_one :host
|
4
4
|
|
5
5
|
def initialize( fields )
|
6
6
|
fields[:target_id] = fields[:target].id
|
@@ -15,5 +15,19 @@ module M2Config
|
|
15
15
|
save
|
16
16
|
end
|
17
17
|
|
18
|
+
def target=( newTarget )
|
19
|
+
self.target_id = newTarget.id
|
20
|
+
self.target_type = newTarget.type
|
21
|
+
save
|
22
|
+
end
|
23
|
+
|
24
|
+
def target
|
25
|
+
case target_type
|
26
|
+
when "proxy" then Proxy[target_id]
|
27
|
+
when "dir" then Dir[target_id]
|
28
|
+
when "handler" then Handler[target_id]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
18
32
|
end
|
19
33
|
end
|
data/lib/m2config/server.rb
CHANGED
@@ -10,7 +10,6 @@ module M2Config
|
|
10
10
|
PORT = 6767
|
11
11
|
USE_SSL = 0
|
12
12
|
|
13
|
-
plugin :validation_helpers
|
14
13
|
one_to_many :hosts
|
15
14
|
|
16
15
|
def initialize( fields={} )
|
@@ -26,12 +25,13 @@ module M2Config
|
|
26
25
|
fields[:use_ssl] ||= USE_SSL
|
27
26
|
super fields, false
|
28
27
|
save
|
29
|
-
end
|
30
|
-
|
31
|
-
def add_host( host )
|
32
|
-
host.server_id = id
|
33
|
-
host.save
|
34
28
|
end
|
35
|
-
|
29
|
+
|
30
|
+
def self.first
|
31
|
+
raise "Careful ! You are calling Server.first on a database holding multiple servers" if
|
32
|
+
((Server.get {count(id)}) > 1)
|
33
|
+
super
|
34
|
+
end
|
35
|
+
|
36
36
|
end
|
37
37
|
end
|
data/lib/m2config/version.rb
CHANGED
data/sample/full.rb
CHANGED
@@ -11,7 +11,7 @@ appHand = M2Config::Handler.new({ send_spec:"tcp://10.0.0.1:8989",
|
|
11
11
|
recv_spec:"tcp://10.0.0.1:9898",
|
12
12
|
send_ident: "dev.example.com ID" })
|
13
13
|
appRoute = M2Config::Route.new( {path:"/blog", target:appHand} )
|
14
|
-
|
14
|
+
|
15
15
|
exComHost.add_route appRoute
|
16
16
|
exComHost.add_route pubRoute
|
17
17
|
|
data/spec/host_spec.rb
CHANGED
@@ -52,5 +52,17 @@ describe M2Config::Host do
|
|
52
52
|
res = @db.get_first_row("SELECT * FROM route;")
|
53
53
|
res["host_id"].should eq(host.id)
|
54
54
|
end
|
55
|
-
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#check_routes' do
|
58
|
+
it 'returns false if some routes have identical paths' do
|
59
|
+
host = M2Config::Host.new({matching:"example.com", name: "ex"})
|
60
|
+
dir1 = M2Config::Dir.new({base: "static/"})
|
61
|
+
dir2 = M2Config::Dir.new({base: "images/"})
|
62
|
+
host.add_route M2Config::Route.new({path:"/blog", target: dir1})
|
63
|
+
host.add_route M2Config::Route.new({path:"/blog", target: dir2})
|
64
|
+
host.check_routes.should be_false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
56
68
|
end
|
data/spec/route_spec.rb
CHANGED
@@ -23,7 +23,6 @@ describe M2Config::Route do
|
|
23
23
|
res["target_id"].should eq(@dirH.id)
|
24
24
|
res["target_type"].should eq(@dirH.type)
|
25
25
|
end
|
26
|
-
|
27
26
|
end
|
28
27
|
|
29
28
|
describe "#host=" do
|
@@ -42,6 +41,32 @@ describe M2Config::Route do
|
|
42
41
|
res = @db.get_first_row("SELECT * FROM route;")
|
43
42
|
res["host_id"].should eq(host.id)
|
44
43
|
end
|
45
|
-
|
46
44
|
end
|
45
|
+
|
46
|
+
describe '#host' do # , {focus: true}
|
47
|
+
it 'returns the associated Host object' do
|
48
|
+
r = M2Config::Route.new({path:"/blog", target: @dirH})
|
49
|
+
r.host = M2Config::Host.new({matching:"example.com", name: "ex"})
|
50
|
+
r.host.matching.should eq("example.com")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#target=' do
|
55
|
+
it 'reassigns the target object' do
|
56
|
+
r = M2Config::Route.new({path:"/blog", target: @dirH})
|
57
|
+
newTarget = M2Config::Proxy.new({addr:"127.0.0.1", port: 15970})
|
58
|
+
r.target = newTarget
|
59
|
+
res = @db.get_first_row("SELECT * FROM route;")
|
60
|
+
res["target_id"].should eq(newTarget.id)
|
61
|
+
res["target_type"].should eq(newTarget.type)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#target' do
|
66
|
+
it 'returns the Target object' do
|
67
|
+
r = M2Config::Route.new({path:"/blog", target: @dirH})
|
68
|
+
r.target.base.should eq @dirH.base
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
47
72
|
end
|
data/spec/server_spec.rb
CHANGED
@@ -9,14 +9,14 @@ describe M2Config::Server do
|
|
9
9
|
@db = SQLite3::Database.new DEFAULT_DB_NAME
|
10
10
|
@db.results_as_hash = true
|
11
11
|
@srv = M2Config::Server.new
|
12
|
-
@host = M2Config::Host.new({matching:"example.com", name: "ex"})
|
12
|
+
@host = M2Config::Host.new({matching:"example.com", name: "ex", server_id:(rand 42)})
|
13
13
|
end
|
14
14
|
|
15
15
|
after(:each) do
|
16
16
|
@db.close if @db && !@db.closed?
|
17
17
|
end
|
18
18
|
|
19
|
-
describe '::new' do
|
19
|
+
describe '::new' do
|
20
20
|
it 'creates a server entry with reasonable default settings' do
|
21
21
|
res= @db.get_first_row("SELECT * FROM server;")
|
22
22
|
res["access_log"].should eq(M2Config::Server::ACCESS_LOG)
|
@@ -32,6 +32,18 @@ describe M2Config::Server do
|
|
32
32
|
|
33
33
|
end
|
34
34
|
|
35
|
+
describe '::first (from Sequel::Model)' do
|
36
|
+
it 'returns the first server found in the database' do
|
37
|
+
srv = M2Config::Server.first
|
38
|
+
srv.id.should eq(@srv.id)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'raises if there is more than one server' do
|
42
|
+
M2Config::Server.new
|
43
|
+
expect { M2Config::Server.first }.to raise_exception /Careful ! You are calling Server.first on a database holding multiple servers/
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
35
47
|
describe '#add_host (assigns the given host to the server)' do
|
36
48
|
it 'accepts an existing Host instance' do
|
37
49
|
@srv.add_host @host
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: m2config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Meuret
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|