sinatra-activerecord 1.2.0 → 1.2.1
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.
- data/README.md +2 -3
- data/lib/sinatra/activerecord.rb +9 -7
- metadata +3 -3
data/README.md
CHANGED
@@ -88,9 +88,8 @@ class User < ActiveRecord::Base
|
|
88
88
|
end
|
89
89
|
```
|
90
90
|
|
91
|
-
You can put your models anywhere you want
|
92
|
-
|
93
|
-
`"sinatra/activerecord"`.
|
91
|
+
You can put your models anywhere you want, only remember to require them if
|
92
|
+
they're in a separate file, and that they're loaded after `require "sinatra/activerecord"`.
|
94
93
|
|
95
94
|
Now everything just works:
|
96
95
|
|
data/lib/sinatra/activerecord.rb
CHANGED
@@ -11,8 +11,8 @@ module Sinatra
|
|
11
11
|
end
|
12
12
|
|
13
13
|
module ActiveRecordExtension
|
14
|
-
def database=(
|
15
|
-
set :
|
14
|
+
def database=(spec)
|
15
|
+
set :database_spec, spec
|
16
16
|
@database = nil
|
17
17
|
database
|
18
18
|
end
|
@@ -20,7 +20,7 @@ module Sinatra
|
|
20
20
|
def database
|
21
21
|
@database ||= begin
|
22
22
|
ActiveRecord::Base.logger = activerecord_logger
|
23
|
-
ActiveRecord::Base.establish_connection(resolve_spec(
|
23
|
+
ActiveRecord::Base.establish_connection(resolve_spec(database_spec))
|
24
24
|
ActiveRecord::Base.connection
|
25
25
|
ActiveRecord::Base
|
26
26
|
end
|
@@ -30,14 +30,16 @@ module Sinatra
|
|
30
30
|
require 'pathname'
|
31
31
|
|
32
32
|
return if app_file.nil?
|
33
|
-
path = File.join(app_file, path) if Pathname.new(path).relative?
|
33
|
+
path = File.join(File.dirname(app_file), path) if Pathname.new(path).relative?
|
34
34
|
|
35
35
|
if File.exists?(path)
|
36
36
|
require 'yaml'
|
37
37
|
require 'erb'
|
38
38
|
|
39
39
|
database_hash = YAML.load(ERB.new(File.read(path)).result) || {}
|
40
|
-
|
40
|
+
if %w[development test production].any? { |env| database_hash[env] }
|
41
|
+
database_hash = database_hash[environment.to_s]
|
42
|
+
end
|
41
43
|
set :database, database_hash
|
42
44
|
end
|
43
45
|
end
|
@@ -46,9 +48,9 @@ module Sinatra
|
|
46
48
|
|
47
49
|
def self.registered(app)
|
48
50
|
app.set :activerecord_logger, Logger.new(STDOUT)
|
49
|
-
app.set :
|
51
|
+
app.set :database_spec, ENV['DATABASE_URL']
|
50
52
|
app.set :database_file, "config/database.yml"
|
51
|
-
app.database if app.
|
53
|
+
app.database if app.database_spec
|
52
54
|
app.helpers ActiveRecordHelper
|
53
55
|
|
54
56
|
# re-connect if database connection dropped
|
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.2.
|
4
|
+
version: 1.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-01-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sinatra
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
segments:
|
126
126
|
- 0
|
127
|
-
hash: -
|
127
|
+
hash: -6445329919965563
|
128
128
|
requirements: []
|
129
129
|
rubyforge_project:
|
130
130
|
rubygems_version: 1.8.23
|