m2config 0.5.4 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1686b2f58b1d2458e9db47c9e88af841b0b15332
4
- data.tar.gz: 7c44815043517753897c2e1a680b9a1956d09990
3
+ metadata.gz: 7628a64cb9b551df57316cd9506e4a27c0711d21
4
+ data.tar.gz: bb8bc8ed05f08fa132f370e9469fd58734c4e480
5
5
  SHA512:
6
- metadata.gz: 3047f3a13d345585396c5181044f560090fa6bfe7990c806df72a80cdfb1b88241e60012b35d07f96131ddeefa58ced9d7bbd754d192d209e65b1fa998f5a38a
7
- data.tar.gz: a2a09aefbb0c124c40182ab9602171e89f386f87d24770fba2a48835ea3442c447afb7657950b6a0b9aca12e04e9a90ab662948b3214a7f6e4b2c8fb2656894b
6
+ metadata.gz: 8d8b93c438183dd08ff388de1dc7716aae67a0403b5e84216330a331fa44e3031e4d9aa85503994ffa602eaf549c43ab88d68c17e62f6aa8787a8dc12253bd69
7
+ data.tar.gz: 66751355ffd58029e51cd2eccbdd65f504d4cd8df36ffab3b55a1b019bf45cb23765f388eee19e1e1d4b342c363594256ab9a02b3f32857250f10c411cd0d8d7
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  CAVEAT EMPTOR
2
2
  -------------
3
3
 
4
- THIS LIB IS VERY YOUNG. ALTHOUGH IT SEEMS TO WORK SO FAR I AM JUST
4
+ THIS LIB IS STILL YOUNG. ALTHOUGH IT SEEMS TO WORK SO FAR, I AM JUST
5
5
  STARTING TO USE IT IN THE FIELD SO EVEN THOUGH THE SPECS PASS IT MAY
6
6
  BREAK STUFF.
7
7
 
@@ -10,7 +10,7 @@ M2config
10
10
  ========
11
11
  [![Build Status](https://travis-ci.org/ameuret/m2config.png?branch=master)](https://travis-ci.org/ameuret/m2config)
12
12
  [![Code Climate](https://codeclimate.com/github/ameuret/m2config.png)](https://codeclimate.com/github/ameuret/m2config)
13
-
13
+ [![Gem Version](https://badge.fury.io/rb/m2config.svg)](http://badge.fury.io/rb/m2config)
14
14
  Manage your Mongrel2 configuration database using handy model classes
15
15
  that map Servers, Hosts, Routes, Directories, Proxies, Handlers and Settings.
16
16
 
@@ -40,8 +40,8 @@ require "m2config"
40
40
 
41
41
  cfg = M2Config::Config.new
42
42
  server = M2Config::Server.new
43
- exComHost = M2Config::Host.new({matching:"example.com"})
44
- pubDir = M2Config::Dir.new({base:"/public"})
43
+ exComHost = M2Config::Host.new({name: "ex", matching:"example.com"})
44
+ pubDir = M2Config::Dir.new({base:"public"})
45
45
  pubRoute = M2Config::Route.new({path:"/", target:pubDir})
46
46
 
47
47
  exComHost.add_route pubRoute
@@ -54,7 +54,7 @@ for duplicates. This has the benefit of complete flexibility and
54
54
  control but *you* must ensure that the DB ends up looking the way you
55
55
  want.
56
56
 
57
- You can swiftly dump your config using:
57
+ You can swiftly dump your config using this at the end of your script:
58
58
 
59
59
  ```ruby
60
60
  require "pp"
@@ -67,6 +67,10 @@ pp Route.all
67
67
 
68
68
  ```
69
69
 
70
+ #### Default values
71
+
72
+ TODO
73
+
70
74
  ### This is Sequel
71
75
 
72
76
  The classes mapping the configuration are
data/lib/m2config.rb CHANGED
@@ -23,12 +23,11 @@ module M2Config
23
23
  @@foundTables
24
24
  end
25
25
 
26
- def initialize( fileName = DEFAULT_CONFIG )
26
+ def initialize(fileName = DEFAULT_CONFIG, options={})
27
27
  @fileName = fileName
28
28
  creating = ! (File.exists? @fileName)
29
29
  @db = Sequel.connect "sqlite://#{@fileName}"
30
30
 
31
-
32
31
  @db.run SCHEMA if creating
33
32
 
34
33
  Sequel::Model.db = @db
@@ -42,7 +41,7 @@ module M2Config
42
41
  require "m2config/setting"
43
42
  require "m2config/mimetype"
44
43
 
45
- M2Config::MimeType.populate_table if creating
44
+ M2Config::MimeType.populate_table(nil,options[:ignoreDoubles]) if creating
46
45
  end
47
46
 
48
47
  def add_server( settings = {} )
@@ -13,12 +13,13 @@ module M2Config
13
13
  having count(*)>1
14
14
  SQL
15
15
 
16
- def self.populate_table
16
+ def self.populate_table(types=nil, ignoreDoubles=false)
17
17
  raise RuntimeError, "Table must be empty" if db[:mimetype].count > 0
18
- rows = []
19
- MIME::Types.each {
18
+ types ||= MIME::Types
19
+ rows = [] # Will collect ext<->type rows
20
+ types.each {
20
21
  |type|
21
- next if not_dominant(type)
22
+ next if not_dominant?(type)
22
23
  type.extensions.each {
23
24
  |ext|
24
25
  ext = "."+ext
@@ -30,18 +31,24 @@ module M2Config
30
31
  db.transaction {
31
32
  db[:mimetype].import([:mimetype, :extension], rows)
32
33
  }
33
- remove_duplicates
34
+ remove_duplicates unless ignoreDoubles
34
35
  end
35
36
 
36
- def self.not_dominant( mtype )
37
- mtype.obsolete? || superceded?(mtype)
37
+ # Is it reasonable to ignore this type ?
38
+ def self.not_dominant?(mtype)
39
+ mtype.obsolete? || superceded?(mtype) || !simplest?(mtype)
38
40
  end
39
41
 
40
- def self.superceded?( mtype )
42
+ def self.superceded?(mtype)
41
43
  mtype.docs =~ /instead/
42
44
  end
45
+
46
+ def self.simplest?(mtype)
47
+ mtype.content_type == mtype.simplified
48
+ end
43
49
 
44
50
  def self.remove_duplicates
51
+ randomChoices = []
45
52
  db[SQL_FIND_DUPLICATES].all.each {
46
53
  |r|
47
54
  ext = r[:extension]
@@ -50,14 +57,14 @@ module M2Config
50
57
  db[:mimetype].where(extension:ext).delete
51
58
  db[:mimetype].insert(extension:ext, mimetype:preferred)
52
59
  else
53
- raise ArgumentError, "#{ext} has multiple content types but no Mongrel2 preference"
60
+ raise ArgumentError, "#{ext} (#{r[:mimetype]}) has multiple content types but no Mongrel2 preference"
54
61
  end
55
62
  }
56
63
  raise RuntimeError, "Still duplicates after removing duplicates!" if
57
64
  db[SQL_FIND_DUPLICATES].all.size > 0
58
65
  end
59
66
 
60
- def initialize( fields )
67
+ def initialize(fields)
61
68
  raise ArgumentError, "Extension must start with a ." unless fields[:extension] =~ /^\./
62
69
  type = M2Config::MimeType[extension:fields[:extension]]
63
70
  raise ArgumentError, "extension #{fields[:extension]} is already covered by #{type.mimetype} type" if type
@@ -854,5 +854,6 @@
854
854
  '.ogv': 'video/ogg'
855
855
  '.oga': 'audio/ogg'
856
856
  '.cmd': 'application/x-msdownload'
857
-
857
+ '.rst': 'text/prs.fallenstein.rst'
858
+ '.sub': 'text/vnd.dvb.subtitle'
858
859
 
@@ -1,3 +1,3 @@
1
1
  module M2Config
2
- VERSION = "0.5.4"
2
+ VERSION = "0.7.0"
3
3
  end
data/m2config.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.add_dependency "sqlite3"
21
21
  spec.add_dependency "sequel", '~> 3'
22
22
  spec.add_dependency "uuid"
23
- spec.add_dependency "mime-types"
23
+ spec.add_dependency "mime-types", '2.4.3'
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.3"
26
26
  spec.add_development_dependency "rake"
data/spec/env.rb CHANGED
@@ -11,7 +11,7 @@ EXISTING_DB_NAME = "empty.sqlite"
11
11
 
12
12
  RSpec.configure do |config|
13
13
  File.delete DEFAULT_DB_NAME rescue nil
14
- CFG = M2Config::Config.new
14
+ CFG = M2Config::Config.new(DEFAULT_DB_NAME,{ignoreDoubles:true})
15
15
  config.around(:each) do |example|
16
16
  CFG.db.transaction do
17
17
  example.call
@@ -21,13 +21,32 @@ describe M2Config::MimeType do
21
21
  end
22
22
 
23
23
  describe '::populate_table' do
24
- it 'fills up the extension to MIME type mapping table' do
24
+ it 'fills up the "extension -> MIME type" mapping table (using the list from https://github.com/halostatue/mime-types)' do
25
25
  # Clear entire table
26
26
  CFG.db[:mimetype].delete
27
- M2Config::MimeType.populate_table
27
+ M2Config::MimeType.populate_table()
28
+ # M2Config::MimeType.populate_table(nil,ignoreDoubles=true)
28
29
  M2Config::MimeType[extension:'.css'].mimetype.should eq('text/css')
29
30
  end
30
31
 
32
+ it 'checks for doubles unless asked not to' do
33
+ CFG.db[:mimetype].delete
34
+ expect {
35
+ M2Config::MimeType.populate_table([
36
+ MIME::Type.new(['text/plain', 'zed']),
37
+ MIME::Type.new(['text/complex', 'zed'])
38
+ ])
39
+ }.to raise_exception(ArgumentError,
40
+ /\.zed \(text\/complex\) has multiple content types but no Mongrel2 preference/i)
41
+ end
42
+
43
+ it 'accepts an array of MIME::Types if the whole list is too much' do
44
+ CFG.db[:mimetype].delete
45
+ M2Config::MimeType.populate_table [MIME::Type.new(['text/plain', 'zed'])]
46
+ M2Config::MimeType[extension:'.zed'].mimetype.should eq('text/plain')
47
+ M2Config::MimeType[extension:'.css'].should eq(nil)
48
+ end
49
+
31
50
  it 'frowns when asked to populate a non-empty table' do
32
51
  # At this point the table has been filled up on creation
33
52
  expect {
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.5.4
4
+ version: 0.7.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: 2014-11-19 00:00:00.000000000 Z
11
+ date: 2014-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: mime-types
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 2.4.3
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 2.4.3
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement