grape-activerecord 1.0.3 → 1.1.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: 00c4596408538956fc799ddf52a5fb064845fd03
|
4
|
+
data.tar.gz: 9da3063fdfaaa9656086a3b2f6689db3cb1ce29d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18c76a4f1c0a5a8610b1d4d0032aecdbcbb016da37c5487c657d754c7b8d71cf15359369a544f2f6f968900e1c4719a2c0161689a4ffa0e5101219cc6515defa
|
7
|
+
data.tar.gz: 2bc91adce6a8182c0687c0f739c1359d46f8edd1dba617ce12b885fd7a2943e20d2b3028a0cd508cb30c20f533028aecb3b88a00294591b7bdbba17cc04b2239
|
data/README.md
CHANGED
@@ -1,50 +1,41 @@
|
|
1
1
|
# grape-activerecord
|
2
2
|
|
3
|
-
A simple way to use ActiveRecord with your Grape apps.
|
3
|
+
A simple way to use ActiveRecord with your Grape apps. The defaults are all very Railsy (`config/database.yml`, `db/seeds.rb`, `db/migrate`, etc.), but you can easily change them.
|
4
4
|
|
5
5
|
## How to use
|
6
6
|
|
7
|
-
|
7
|
+
#### 1. Add it to your Gemfile
|
8
8
|
|
9
9
|
gem "grape-activerecord"
|
10
10
|
|
11
|
-
|
11
|
+
#### 2. Configure your database connection
|
12
12
|
|
13
|
-
grape-activerecord looks for your database configuration in:
|
13
|
+
By default grape-activerecord looks for your database configuration in:
|
14
14
|
|
15
15
|
* `config/database.yml` (see /examples for a sample file)
|
16
16
|
* The `DATABASE_URL` environment variable (e.g. `postgres://user:pass@host/db`)
|
17
17
|
|
18
|
-
|
18
|
+
#### 3. Enable ActiveRecord connection management
|
19
19
|
|
20
|
-
|
21
|
-
Grape::ActiveRecord.database_url = "postgres://user:pass@host/db"
|
22
|
-
Grape::ActiveRecord.database = {adapter: "postgresql", host: "localhost", database: "db", username: "user", password: "pass", encoding: "utf8", pool: 10, timeout: 5000}
|
23
|
-
|
24
|
-
### 3. Enable ActiveRecord connection management
|
25
|
-
|
26
|
-
This ActiveRecord middleware cleans up your database connections after each request. Add it to your config.ru file:
|
20
|
+
This ActiveRecord middleware cleans up your database connections after each request. Add it to your `config.ru` file:
|
27
21
|
|
28
22
|
use ActiveRecord::ConnectionAdapters::ConnectionManagement
|
29
23
|
|
30
|
-
|
24
|
+
#### 4. Import ActiveRecord tasks into your Rakefile
|
31
25
|
|
32
|
-
This will give you most of the standard `db:` tasks you get in Rails.
|
26
|
+
This will give you most of the standard `db:` tasks you get in Rails. Add it to your `Rakefile`.
|
33
27
|
|
34
28
|
require "bundler/setup"
|
35
29
|
require "grape/activerecord/rake"
|
36
30
|
|
37
31
|
namespace :db do
|
38
|
-
# Some db tasks require your app code to be loaded
|
32
|
+
# Some db tasks require your app code to be loaded, or at least your gems
|
39
33
|
task :environment do
|
40
|
-
# If you set a custom db config in your app, you'll need to set it in your Rakefile too
|
41
|
-
# Grape::ActiveRecord.database_file = "elsewhere/db.yml"
|
42
|
-
|
43
34
|
require_relative "app"
|
44
35
|
end
|
45
36
|
end
|
46
37
|
|
47
|
-
Unlike in Rails, creating a new migration is also a rake task
|
38
|
+
Unlike in Rails, creating a new migration is also a rake task. Run `bundle exec rake -T` to get a full list.
|
48
39
|
|
49
40
|
bundle exec rake db:create_migration NAME=create_widgets
|
50
41
|
|
@@ -52,6 +43,21 @@ Unlike in Rails, creating a new migration is also a rake task:
|
|
52
43
|
|
53
44
|
Look under /examples for some example apps.
|
54
45
|
|
46
|
+
## Advanced options
|
47
|
+
|
48
|
+
You have a number of ways to tell ActiveRecord about your database. Use these options early in your app's boot process: somewhere between bundler and your app code. And make sure they make it into your `Rakefile` (maybe in `require_relative "app"` above.)
|
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.
|
55
|
+
|
56
|
+
Grape::ActiveRecord.db_dir = 'db'
|
57
|
+
Grape::ActiveRecord.migrations_paths = ['db/migrate']
|
58
|
+
Grape::ActiveRecord.fixtures_path = 'test/fixtures'
|
59
|
+
Grape::ActiveRecord.seed_file = 'seeds.rb'
|
60
|
+
|
55
61
|
## License
|
56
62
|
|
57
63
|
Licensed under the MIT License
|
@@ -2,6 +2,17 @@
|
|
2
2
|
module Grape
|
3
3
|
# Grape and ActiveRecord integration
|
4
4
|
module ActiveRecord
|
5
|
+
class << self
|
6
|
+
# Relative path to the "db" dir
|
7
|
+
attr_accessor :db_dir
|
8
|
+
# Relative path(s) to the migrations directory
|
9
|
+
attr_accessor :migrations_paths
|
10
|
+
# Relative path to the fixtures directory
|
11
|
+
attr_accessor :fixtures_path
|
12
|
+
# Name of the seeds file in db_dir
|
13
|
+
attr_accessor :seed_file
|
14
|
+
end
|
15
|
+
|
5
16
|
# The current Rack environment
|
6
17
|
RACK_ENV = (ENV['RACK_ENV'] || 'development').to_sym
|
7
18
|
|
@@ -6,3 +6,8 @@ if ENV['DATABASE_URL']
|
|
6
6
|
elsif File.file? 'config/database.yml'
|
7
7
|
Grape::ActiveRecord.database_file = 'config/database.yml'
|
8
8
|
end
|
9
|
+
|
10
|
+
Grape::ActiveRecord.db_dir = 'db'
|
11
|
+
Grape::ActiveRecord.migrations_paths = %w(db/migrate)
|
12
|
+
Grape::ActiveRecord.fixtures_path = 'test/fixtures'
|
13
|
+
Grape::ActiveRecord.seed_file = 'seeds.rb'
|
@@ -5,14 +5,14 @@ Rake::Task.define_task('db:_load_config') do
|
|
5
5
|
ActiveRecord::Tasks::DatabaseTasks.tap do |config|
|
6
6
|
config.root = Rake.application.original_dir
|
7
7
|
config.env = Grape::ActiveRecord::RACK_ENV.to_s
|
8
|
-
config.db_dir =
|
9
|
-
config.migrations_paths =
|
10
|
-
config.fixtures_path =
|
8
|
+
config.db_dir = Grape::ActiveRecord.db_dir
|
9
|
+
config.migrations_paths = Array(Grape::ActiveRecord.migrations_paths)
|
10
|
+
config.fixtures_path = Grape::ActiveRecord.fixtures_path
|
11
11
|
config.database_configuration = ActiveRecord::Base.configurations
|
12
12
|
config.seed_loader = Object.new
|
13
13
|
config.seed_loader.instance_eval do
|
14
14
|
def load_seed
|
15
|
-
load "#{ActiveRecord::Tasks::DatabaseTasks.db_dir}
|
15
|
+
load "#{ActiveRecord::Tasks::DatabaseTasks.db_dir}/#{Grape::ActiveRecord.seed_file}"
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
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: 1.0
|
4
|
+
version: 1.1.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: 2015-
|
11
|
+
date: 2015-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|