sinatra-activerecord 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +12 -5
  2. data/lib/sinatra/activerecord.rb +18 -1
  3. metadata +18 -21
data/README.md CHANGED
@@ -29,10 +29,13 @@ Now specify the database in your `app.rb`
29
29
  require 'sinatra'
30
30
  require 'sinatra/activerecord'
31
31
 
32
- set :database, 'sqlite:///foo.db'
32
+ set :database, 'sqlite3:///foo.db'
33
33
  ```
34
34
 
35
- Note that in **modular** Sinatra applications (ones in which you explicitly
35
+ Note that the database URL here has **3** slashes. This is the difference from
36
+ <= 1.0.0 versions, where it was typed with 2 slashes.
37
+
38
+ Also note that in **modular** Sinatra applications (ones in which you explicitly
36
39
  subclass `Sinatra::Base`), you will need to manually add the line:
37
40
 
38
41
  ```ruby
@@ -48,7 +51,7 @@ require './app'
48
51
 
49
52
  In the Terminal test that it works:
50
53
 
51
- ```
54
+ ```sh
52
55
  $ rake -T
53
56
  rake db:create_migration # create an ActiveRecord migration in ./db/migrate
54
57
  rake db:migrate # migrate your database
@@ -56,7 +59,7 @@ rake db:migrate # migrate your database
56
59
 
57
60
  Now you can create a migration:
58
61
 
59
- ```
62
+ ```sh
60
63
  $ rake db:create_migration NAME=create_users
61
64
  ```
62
65
 
@@ -78,7 +81,7 @@ end
78
81
 
79
82
  After you've written the migration, migrate the database:
80
83
 
81
- ```
84
+ ```sh
82
85
  $ rake db:migrate
83
86
  ```
84
87
 
@@ -130,6 +133,10 @@ You can see the changelog
130
133
 
131
134
  This gem was made in 2009 by Blake Mizerany, one of the authors of Sinatra.
132
135
 
136
+ ## Social
137
+
138
+ You can follow me on Twitter, I'm [@m_janko](http://twitter.com/m_janko).
139
+
133
140
  ## License
134
141
 
135
142
  [MIT](https://github.com/janko-m/sinatra-activerecord/blob/master/LICENSE)
@@ -1,6 +1,7 @@
1
1
  require 'sinatra/base'
2
2
  require 'active_record'
3
3
  require 'logger'
4
+ require 'active_support/core_ext/string/strip'
4
5
 
5
6
  module Sinatra
6
7
  module ActiveRecordHelper
@@ -19,7 +20,7 @@ module Sinatra
19
20
  def database
20
21
  @database ||= begin
21
22
  ActiveRecord::Base.logger = activerecord_logger
22
- spec = database_url.is_a?(String) ? database_url.sub(/^sqlite:/, "sqlite3:") : database_url
23
+ spec = resolve_spec(database_url)
23
24
  ActiveRecord::Base.establish_connection(spec)
24
25
  ActiveRecord::Base
25
26
  end
@@ -37,6 +38,22 @@ module Sinatra
37
38
  app.before { ActiveRecord::Base.verify_active_connections! }
38
39
  app.after { ActiveRecord::Base.clear_active_connections! }
39
40
  end
41
+
42
+ private
43
+
44
+ def resolve_spec(database_url)
45
+ if database_url.is_a?(String)
46
+ if database_url =~ %r{^sqlite3?://[A-Za-z_-]+\.(db|sqlite3?)$}
47
+ warn <<-MESSAGE.strip_heredoc
48
+ It seems your database URL looks something like this: "sqlite3://<database_name>".
49
+ This doesn't work anymore, you need to use 3 slashes, like this: "sqlite3:///<database_name>".
50
+ MESSAGE
51
+ end
52
+ database_url.sub(/^sqlite:/, "sqlite3:")
53
+ else
54
+ database_url
55
+ end
56
+ end
40
57
  end
41
58
 
42
59
  register ActiveRecordExtension
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-22 00:00:00.000000000 Z
12
+ date: 2012-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -44,48 +44,45 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '3.0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: bundler
47
+ name: rake
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ~>
51
+ - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
- version: '1.0'
53
+ version: '0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ~>
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
- version: '1.0'
61
+ version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
- name: rake
63
+ name: rspec
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ~>
67
+ - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
- version: '0.9'
69
+ version: '2.10'
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ~>
75
+ - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
- version: '0.9'
77
+ version: '2.10'
78
78
  - !ruby/object:Gem::Dependency
79
- name: rspec
79
+ name: sqlite3
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
83
  - - ! '>='
84
84
  - !ruby/object:Gem::Version
85
- version: '2.10'
86
- - - <
87
- - !ruby/object:Gem::Version
88
- version: '3'
85
+ version: '0'
89
86
  type: :development
90
87
  prerelease: false
91
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -93,10 +90,7 @@ dependencies:
93
90
  requirements:
94
91
  - - ! '>='
95
92
  - !ruby/object:Gem::Version
96
- version: '2.10'
97
- - - <
98
- - !ruby/object:Gem::Version
99
- version: '3'
93
+ version: '0'
100
94
  description: Extends Sinatra with ActiveRecord helpers.
101
95
  email: janko.marohnic@gmail.com
102
96
  executables: []
@@ -127,6 +121,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
121
  - - ! '>='
128
122
  - !ruby/object:Gem::Version
129
123
  version: '0'
124
+ segments:
125
+ - 0
126
+ hash: -2180039102864061955
130
127
  requirements: []
131
128
  rubyforge_project:
132
129
  rubygems_version: 1.8.23