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: 277fa119f61a75f2b6920ad1e4b885d23e687fc3
4
- data.tar.gz: 30829e43950d647ceb2290983c6121948863b9fb
3
+ metadata.gz: 00c4596408538956fc799ddf52a5fb064845fd03
4
+ data.tar.gz: 9da3063fdfaaa9656086a3b2f6689db3cb1ce29d
5
5
  SHA512:
6
- metadata.gz: 6377dc5c48e482106997bc2a75aa238dac39c09b3a2eebdd5ba85392518742d1eb8accdc5de240585b5daa223ae263f3c9f8f05eaa332d58ddbf1a879fb056a7
7
- data.tar.gz: 03cada4ffaa98838717c078b1a18d5c30f61d6e66fc0ca5eb8e104413e54f9f466492e37ccc018c15b4be99760884a2810fb7479cc6ad93aaa83de457b9d4f8f
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
- ### 1. Add it to your Gemfile
7
+ #### 1. Add it to your Gemfile
8
8
 
9
9
  gem "grape-activerecord"
10
10
 
11
- ### 2. Configure your database connection
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
- But if your app has more particular needs, we've got you covered:
18
+ #### 3. Enable ActiveRecord connection management
19
19
 
20
- Grape::ActiveRecord.database_file = "elsewhere/db.yml"
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
- ### 4. Import ActiveRecord tasks into your Rakefile
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. Run `bundle exec rake -T` to get a full list.
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 = 'db'
9
- config.migrations_paths = ['db/migrate']
10
- config.fixtures_path = 'test/fixtures'
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}/seeds.rb"
15
+ load "#{ActiveRecord::Tasks::DatabaseTasks.db_dir}/#{Grape::ActiveRecord.seed_file}"
16
16
  end
17
17
  end
18
18
  end
@@ -1,3 +1,4 @@
1
+ require 'grape/activerecord'
1
2
  load "active_record/railties/databases.rake"
2
3
  require "grape/activerecord/rake/activerecord_#{ActiveRecord::VERSION::MAJOR}"
3
4
  load "grape/activerecord/tasks.rake"
@@ -1,6 +1,6 @@
1
1
  module Grape
2
2
  module ActiveRecord
3
3
  # Gem version
4
- VERSION = '1.0.3'
4
+ VERSION = '1.1.0'
5
5
  end
6
6
  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.3
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-08-28 00:00:00.000000000 Z
11
+ date: 2015-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape