grape-activerecord 1.1.2 → 2.0.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27a4153d9aa6bac32066254f76353d8608d5637d
|
4
|
+
data.tar.gz: 2d83a5e15433ca0ad19d360caa99b6150bb2f50e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73c43881ff83cc9cdf96a171b3f1f3de3b156c739eac11f0405d1af12959b0cbdfe3f26e0d2a36a352285dc6f408a8ae3e2f19ddcc7d3c4892b6122e904e7c59
|
7
|
+
data.tar.gz: 5ba35e8d13f810a4ccf2aeec5184e67ab371ffc26b51b36d27873558241f2e6106adadcfd64f3253f21767dbecfd24021cd2de4f530df2bf1ab1aa781aa985bd
|
data/README.md
CHANGED
@@ -10,10 +10,11 @@ A simple way to use ActiveRecord with your Grape apps. The defaults are all very
|
|
10
10
|
|
11
11
|
#### 2. Configure your database connection
|
12
12
|
|
13
|
-
|
13
|
+
After loading your gems, tell `Grape::ActiveRecord` about your database config using one of the following examples:
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
Grape::ActiveRecord.configure_from_file! "config/database.yml"
|
16
|
+
Grape::ActiveRecord.configure_from_url! ENV['DATABASE_URL'] # e.g. postgres://user:pass@host/db
|
17
|
+
Grape::ActiveRecord.configure_from_hash!(adapter: "postgresql", host: "localhost", database: "db", username: "user", password: "pass", encoding: "utf8", pool: 10, timeout: 5000)
|
17
18
|
|
18
19
|
#### 3. Enable ActiveRecord connection management
|
19
20
|
|
@@ -41,17 +42,11 @@ Unlike in Rails, creating a new migration is also a rake task. Run `bundle exec
|
|
41
42
|
|
42
43
|
## Examples
|
43
44
|
|
44
|
-
Look under /
|
45
|
+
Look under /example for an example app.
|
45
46
|
|
46
47
|
## Advanced options
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
Grape::ActiveRecord.database_file = "elsewhere/db.yml"
|
51
|
-
Grape::ActiveRecord.database_url = "postgres://user:pass@host/db"
|
52
|
-
Grape::ActiveRecord.database = {adapter: "postgresql", host: "localhost", database: "db", username: "user", password: "pass", encoding: "utf8", pool: 10, timeout: 5000}
|
53
|
-
|
54
|
-
You can configure custom locations for your db-related files like migrations, seeds, and fixtures. You should probably put these near the top of your `Rakefile`, before defining your tasks.
|
49
|
+
The defaults for db-related files like migrations, seeds, and fixtures are the same as Rails. If you want to override them, use the following options in your `Rakefile`:
|
55
50
|
|
56
51
|
Grape::ActiveRecord.db_dir = 'db'
|
57
52
|
Grape::ActiveRecord.migrations_paths = ['db/migrate']
|
@@ -15,18 +15,18 @@ module Grape
|
|
15
15
|
|
16
16
|
# Connect to database with a Hash. Example:
|
17
17
|
# {adapter: 'postgresql', host: 'localhost', database: 'db', username: 'user', password: 'pass', encoding: 'utf8', pool: 10, timeout: 5000}
|
18
|
-
def self.
|
18
|
+
def self.configure_from_hash!(spec)
|
19
19
|
::ActiveRecord::Base.configurations = {rack_env => spec}.stringify_keys
|
20
20
|
::ActiveRecord::Base.establish_connection(rack_env)
|
21
21
|
end
|
22
22
|
|
23
23
|
# Connect to database with a DB URL. Example: "postgres://user:pass@localhost/db"
|
24
|
-
def self.
|
25
|
-
|
24
|
+
def self.configure_from_url!(url)
|
25
|
+
configure_from_hash! ::ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver.new(url).to_hash
|
26
26
|
end
|
27
27
|
|
28
28
|
# Connect to database with a yml file. Example: "config/database.yml"
|
29
|
-
def self.
|
29
|
+
def self.configure_from_file!(path)
|
30
30
|
raise "#{path} does not exist!" unless File.file? path
|
31
31
|
::ActiveRecord::Base.configurations = YAML.load(ERB.new(File.read(path)).result) || {}
|
32
32
|
::ActiveRecord::Base.establish_connection(rack_env)
|
@@ -1,12 +1,6 @@
|
|
1
1
|
::ActiveRecord::Base.default_timezone = :utc
|
2
2
|
::ActiveRecord::Base.logger = Logger.new(STDOUT)
|
3
3
|
|
4
|
-
if ENV['DATABASE_URL']
|
5
|
-
Grape::ActiveRecord.database_url = ENV['DATABASE_URL']
|
6
|
-
elsif File.file? 'config/database.yml'
|
7
|
-
Grape::ActiveRecord.database_file = 'config/database.yml'
|
8
|
-
end
|
9
|
-
|
10
4
|
Grape::ActiveRecord.db_dir = 'db'
|
11
5
|
Grape::ActiveRecord.migrations_paths = %w(db/migrate)
|
12
6
|
Grape::ActiveRecord.fixtures_path = 'test/fixtures'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Hollinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|