m2config 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8af32f60790056db4c869961bf53572607910579
4
+ data.tar.gz: 94bece67112686d6f40e58a5f57647b869dbb8d0
5
+ SHA512:
6
+ metadata.gz: a85f7fc5d80cb047a69494d85a433cf598b5dc22703c5bc509056b9027f93ebb7410b7b3646160fe02d730447abd2b86f877356787ed8ce1b98405637d4b5074
7
+ data.tar.gz: d5b4d69be4e351300217f8c5ae0414fbb4926d388d6ddab722a7e54da1e50aee5fb80c187d25ff770102ce9123e773c634fe0e1f3d051e10bf641ec1c10d31b0
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/README.md CHANGED
@@ -48,6 +48,25 @@ exComHost.add_route pubRoute
48
48
  server.add_host exComHost
49
49
  ```
50
50
 
51
+ Keep in mind that these lines will create their corresponding database
52
+ records every time the script is run. For simplicity there is no check
53
+ for duplicates. This has the benefit of complete flexibility and
54
+ control but *you* must ensure that the DB ends up looking the way you
55
+ want.
56
+
57
+ You can swiftly dump your config using:
58
+
59
+ ```ruby
60
+ require "pp"
61
+
62
+ pp Server.all
63
+ pp Host.all
64
+ pp Handler.all
65
+ pp Dir.all
66
+ pp Route.all
67
+
68
+ ```
69
+
51
70
  ### This is Sequel
52
71
 
53
72
  The classes mapping the configuration are
@@ -61,7 +80,9 @@ A few features that you may miss if your needs go beyond mine:
61
80
 
62
81
  - MIME types are not handled (trivial to add, just ask)
63
82
  - Multiple DBs in same process
64
- - A DSL-like syntax (probably improves readability in complex setups)
83
+ - A DSL-like syntax (likely to improve readability in complex setups)
84
+ - Declare proper associations
85
+ - Cleanup / consolidate DB (delete unreferenced entries)
65
86
 
66
87
 
67
88
 
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/lib/m2config/dir.rb CHANGED
@@ -5,6 +5,10 @@ module M2Config
5
5
  def initialize( fields )
6
6
  fields[:default_ctype] ||= "application/octet-stream"
7
7
  fields[:index_file] ||= "index.html"
8
+ raise ArgumentError, "Base directories are relative to chroot and must not start with a slash (as in your <#{fields[:base]}>)" if
9
+ fields[:base] =~ /^\/.+/
10
+ raise ArgumentError, "Base directories must end with a slash (your <#{fields[:base]}> does not)" if
11
+ !(fields[:base] =~ /\/$/)
8
12
  super(fields, false)
9
13
  save
10
14
  end
@@ -5,6 +5,7 @@ module M2Config
5
5
  def initialize( fields )
6
6
  raise ArgumentError, "The send and receive endpoints can not be the same" if
7
7
  fields[:send_spec] == fields[:recv_spec]
8
+ fields[:recv_ident] ||= ""
8
9
  super(fields, false)
9
10
  save
10
11
  end
data/lib/m2config/host.rb CHANGED
@@ -3,6 +3,20 @@ module M2Config
3
3
  plugin :validation_helpers
4
4
 
5
5
  def initialize( fields )
6
+ s = resolveServer fields
7
+ fields[:server_id] = s.id if s
8
+ raise ArgumentError, "Name can not be nil" if fields[:name].nil?
9
+ super fields, false
10
+ save
11
+ end
12
+
13
+ def add_route( route )
14
+ route.host = id
15
+ end
16
+
17
+ private
18
+
19
+ def resolveServer( fields )
6
20
  if fields[:srv]
7
21
  s=fields[:srv]
8
22
  fields.delete :srv
@@ -12,13 +26,7 @@ module M2Config
12
26
  fields.delete :srvUuid
13
27
  end
14
28
  end
15
- fields[:server_id] = s.id if s
16
- super(fields, false)
17
- save
18
- end
19
-
20
- def add_route( route )
21
- route.host = id
29
+ s
22
30
  end
23
31
 
24
32
 
@@ -52,3 +52,7 @@ CREATE TABLE statistic (id SERIAL,
52
52
  mean REAL,
53
53
  sd REAL,
54
54
  primary key (other_type, other_id, name));
55
+ CREATE TABLE filter (id INTEGER PRIMARY KEY,
56
+ server_id INTEGER,
57
+ name TEXT,
58
+ settings TEXT);
@@ -1,3 +1,3 @@
1
1
  module M2Config
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/m2config.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
  spec.add_development_dependency "rake"
26
+ spec.required_ruby_version = '>= 1.9.0'
26
27
  end
data/sample/full.rb CHANGED
@@ -3,14 +3,14 @@ require "m2config"
3
3
  include M2Config
4
4
 
5
5
  cfg = M2Config::Config.new
6
- server = Server.new
7
- exComHost = Host.new({matching:"example.com"})
8
- pubDir = Dir.new({base:"/public"})
9
- pubRoute = Route.new( {path:"/", target:pubDir} )
10
- appHand = Handler.new({ send_spec:"tcp://10.0.0.1:8989",
6
+ server = M2Config::Server.new
7
+ exComHost = M2Config::Host.new({matching:"example.com", name:"ex"})
8
+ pubDir = M2Config::Dir.new({base:"public/"})
9
+ pubRoute = M2Config::Route.new( {path:"/", target:pubDir} )
10
+ 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
- appRoute = Route.new( {path:"/blog", target:appHand} )
13
+ appRoute = M2Config::Route.new( {path:"/blog", target:appHand} )
14
14
 
15
15
  exComHost.add_route appRoute
16
16
  exComHost.add_route pubRoute
data/spec/dir_spec.rb CHANGED
@@ -16,13 +16,13 @@ describe M2Config::Dir do
16
16
 
17
17
  describe "::new" do
18
18
  it "needs to know the base path to handle" do
19
- M2Config::Dir.new({base:"/images"})
19
+ M2Config::Dir.new({base:"images/"})
20
20
  res= @db.get_first_row("SELECT * FROM directory;")
21
- res["base"].should eq("/images")
21
+ res["base"].should eq("images/")
22
22
  end
23
23
 
24
24
  it "defaults to application/octet-stream for the default content type" do
25
- M2Config::Dir.new({base:"/images"})
25
+ M2Config::Dir.new({base:"images/"})
26
26
  res= @db.get_first_row("SELECT * FROM directory;")
27
27
  res["default_ctype"].should eq("application/octet-stream")
28
28
  end
@@ -32,6 +32,25 @@ describe M2Config::Dir do
32
32
  res= @db.get_first_row("SELECT * FROM directory;")
33
33
  res["index_file"].should eq("index.html")
34
34
  end
35
+
36
+ describe "helps you spot common mistakes" do
37
+ it "yells when the path contains a leading slash" do
38
+ expect {
39
+ M2Config::Dir.new({base:"/public"})
40
+ }.to raise_exception(ArgumentError, /base directories are relative to chroot and must not start with a slash/i)
41
+ end
42
+
43
+ it "yells when the path does not end with a slash" do
44
+ expect {
45
+ M2Config::Dir.new({base:"public"})
46
+ }.to raise_exception(ArgumentError, /base directories must end with a slash/i)
47
+ end
48
+
49
+ it "keeps calm with slashes inside the path" do
50
+ expect { M2Config::Dir.new({base:"public/assets/"}) }.to_not raise_exception
51
+ end
52
+
53
+ end
35
54
  end
36
55
 
37
56
  describe '#type' do
data/spec/handler_spec.rb CHANGED
@@ -25,6 +25,14 @@ describe M2Config::Handler do
25
25
  res["recv_spec"].should eq("tcp://10.0.0.1:9898")
26
26
  res["send_ident"].should eq("dev.example.com ID")
27
27
  end
28
+
29
+ it "turns nil into empty string when recv_ident is not set" do
30
+ M2Config::Handler.new({ send_spec:"tcp://10.0.0.1:8989",
31
+ recv_spec:"tcp://10.0.0.1:9898",
32
+ send_ident: "dev.example.com ID"})
33
+ res = @db.get_first_row("SELECT * FROM handler;")
34
+ res["recv_ident"].should be_empty
35
+ end
28
36
 
29
37
  describe "helps you spot common mistakes" do
30
38
  it "yells when the addresses are the same" do
@@ -32,6 +40,7 @@ describe M2Config::Handler do
32
40
  M2Config::Handler.new({send_spec:"tcp://10.0.0.1:8989", recv_spec:"tcp://10.0.0.1:8989", send_ident: "dev.example.com ID"})
33
41
  end.to raise_exception(ArgumentError, /send and receive endpoints can not be the same/i)
34
42
  end
43
+
35
44
  end
36
45
  end
37
46
 
data/spec/host_spec.rb CHANGED
@@ -17,30 +17,36 @@ describe M2Config::Host do
17
17
 
18
18
  describe "::new" do
19
19
  it "needs to know the domain name served" do
20
- M2Config::Host.new({matching:"example.com"})
20
+ M2Config::Host.new({matching:"example.com", name: "ex"})
21
21
  res = @db.get_first_row("SELECT * FROM host;")
22
22
  res["matching"].should eq("example.com")
23
23
  end
24
24
 
25
25
  it "can use the uuid of a server" do
26
- host = M2Config::Host.new({matching:"example.com", srvUuid: @srv.uuid})
26
+ host = M2Config::Host.new({matching:"example.com", name: "ex", srvUuid: @srv.uuid})
27
27
  res = @db.get_first_row("SELECT * FROM host WHERE id=?;", host.id)
28
28
  res["server_id"].should eq(@srv.id)
29
29
  res["matching"].should eq("example.com")
30
30
  end
31
31
 
32
32
  it "can use a server instance" do
33
- host = M2Config::Host.new({matching:"example.com", srv: @srv})
33
+ host = M2Config::Host.new({matching:"example.com", name: "ex", srv: @srv})
34
34
  res = @db.get_first_row("SELECT * FROM host WHERE id=?;", host.id)
35
35
  res["server_id"].should eq(@srv.id)
36
36
  res["matching"].should eq("example.com")
37
37
  end
38
+
39
+ it "enforces mongrel2 constraint about nil name" do
40
+ expect {
41
+ M2Config::Host.new({matching:"example.com"})
42
+ }.to raise_exception(ArgumentError, /name can not be nil/i)
43
+ end
38
44
  end
39
45
 
40
46
  describe "#add_route" do
41
47
  it "activates a route (can be done using Route#host= too)" do
42
- host = M2Config::Host.new({matching:"example.com"})
43
- dirH = M2Config::Dir.new({base: "/static"})
48
+ host = M2Config::Host.new({matching:"example.com", name: "ex"})
49
+ dirH = M2Config::Dir.new({base: "static/"})
44
50
  dirR = M2Config::Route.new({path:"/blog", target: dirH})
45
51
  host.add_route dirR
46
52
  res = @db.get_first_row("SELECT * FROM route;")
@@ -1,6 +1,6 @@
1
1
  require "env"
2
2
 
3
- TABLES = %w(directory handler host log mimetype proxy route server setting statistic)
3
+ TABLES = %w(directory handler host log mimetype proxy route server setting statistic filter)
4
4
 
5
5
  File.delete EXISTING_DB_NAME rescue nil
6
6
  emptyDB = SQLite3::Database.new EXISTING_DB_NAME
data/spec/route_spec.rb CHANGED
@@ -6,7 +6,7 @@ describe M2Config::Route do
6
6
  before(:each) do
7
7
  File.delete DEFAULT_DB_NAME rescue nil
8
8
  @cfg = M2Config::Config.new
9
- @dirH = M2Config::Dir.new({base: "/static"})
9
+ @dirH = M2Config::Dir.new({base: "static/"})
10
10
  @db = SQLite3::Database.new DEFAULT_DB_NAME
11
11
  @db.results_as_hash = true
12
12
  end
@@ -28,7 +28,7 @@ describe M2Config::Route do
28
28
 
29
29
  describe "#host=" do
30
30
  it "can be used if the host is not known at creation" do
31
- host = M2Config::Host.new({matching:"example.com"})
31
+ host = M2Config::Host.new({matching:"example.com", name: "ex"})
32
32
  r = M2Config::Route.new({path:"/blog", target: @dirH})
33
33
  r.host = host.id
34
34
  res = @db.get_first_row("SELECT * FROM route;")
@@ -36,7 +36,7 @@ describe M2Config::Route do
36
36
  end
37
37
 
38
38
  it "can take a Host instance" do
39
- host = M2Config::Host.new({matching:"example.com"})
39
+ host = M2Config::Host.new({matching:"example.com", name: "ex"})
40
40
  r = M2Config::Route.new({path:"/blog", target: @dirH})
41
41
  r.host = host
42
42
  res = @db.get_first_row("SELECT * FROM route;")
data/spec/server_spec.rb CHANGED
@@ -9,7 +9,7 @@ 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"})
12
+ @host = M2Config::Host.new({matching:"example.com", name: "ex"})
13
13
  end
14
14
 
15
15
  after(:each) do
metadata CHANGED
@@ -1,68 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: m2config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Arnaud Meuret
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-21 00:00:00.000000000 Z
11
+ date: 2013-03-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: sqlite3
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: sequel
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: uuid
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: bundler
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,17 +69,15 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rake
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  description: A library to easily manage a Mongrel2 configuration database
@@ -99,6 +88,7 @@ extensions: []
99
88
  extra_rdoc_files: []
100
89
  files:
101
90
  - .gitignore
91
+ - .travis.yml
102
92
  - Gemfile
103
93
  - Guardfile
104
94
  - LICENSE
@@ -128,33 +118,26 @@ files:
128
118
  homepage: https://github.com/ameuret/m2config
129
119
  licenses:
130
120
  - MIT
121
+ metadata: {}
131
122
  post_install_message:
132
123
  rdoc_options: []
133
124
  require_paths:
134
125
  - lib
135
126
  required_ruby_version: !ruby/object:Gem::Requirement
136
- none: false
137
127
  requirements:
138
- - - ! '>='
128
+ - - '>='
139
129
  - !ruby/object:Gem::Version
140
- version: '0'
141
- segments:
142
- - 0
143
- hash: -327752419
130
+ version: 1.9.0
144
131
  required_rubygems_version: !ruby/object:Gem::Requirement
145
- none: false
146
132
  requirements:
147
- - - ! '>='
133
+ - - '>='
148
134
  - !ruby/object:Gem::Version
149
135
  version: '0'
150
- segments:
151
- - 0
152
- hash: -327752419
153
136
  requirements: []
154
137
  rubyforge_project:
155
- rubygems_version: 1.8.25
138
+ rubygems_version: 2.0.3
156
139
  signing_key:
157
- specification_version: 3
140
+ specification_version: 4
158
141
  summary: Manage your Mongrel2 configuration database using handy model classes that
159
142
  map Servers, Hosts, Routes, Directories, Proxies, Handlers and Settings
160
143
  test_files: