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: 9f83ac0f6b25c75518fffd13df7a06930991b22f
4
- data.tar.gz: ed53c8b92a279c6912fa916cb6ef3bae52d068ae
3
+ metadata.gz: 27a4153d9aa6bac32066254f76353d8608d5637d
4
+ data.tar.gz: 2d83a5e15433ca0ad19d360caa99b6150bb2f50e
5
5
  SHA512:
6
- metadata.gz: d3abd75b1d54a68ff81293a2921756308c4540f0847c1373444bfabe88a92a7aafe366962b5b3ce65d759fd583e1423dff0410b4e8fa2408d22920d4d852329a
7
- data.tar.gz: 3b124647b93b0f50c81da91a8fdb3beca20d67e7bfda176b4f4f46b7b7ddcfeeb706d0e0731296f80cd7b99e55cb0bf63f1937cc5bb55f1497e872d86c88c9cc
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
- By default grape-activerecord looks for your database configuration in:
13
+ After loading your gems, tell `Grape::ActiveRecord` about your database config using one of the following examples:
14
14
 
15
- * `config/database.yml` (see /examples for a sample file)
16
- * The `DATABASE_URL` environment variable (e.g. `postgres://user:pass@host/db`)
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 /examples for some example apps.
45
+ Look under /example for an example app.
45
46
 
46
47
  ## Advanced options
47
48
 
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.
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.database=(spec)
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.database_url=(url)
25
- self.database = ::ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver.new(url).to_hash
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.database_file=(path)
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'
@@ -1,4 +1,4 @@
1
- require 'grape/activerecord/activerecord'
1
+ require 'grape/activerecord'
2
2
  load "active_record/railties/databases.rake"
3
3
  require "grape/activerecord/rake/activerecord_#{ActiveRecord::VERSION::MAJOR}"
4
4
  load "grape/activerecord/tasks.rake"
@@ -1,5 +1,4 @@
1
1
  Rake::Task.define_task('db:_load_config') do
2
- require 'grape/activerecord'
3
2
  ActiveRecord::Base.logger = nil
4
3
 
5
4
  ActiveRecord::Tasks::DatabaseTasks.tap do |config|
@@ -1,6 +1,6 @@
1
1
  module Grape
2
2
  module ActiveRecord
3
3
  # Gem version
4
- VERSION = '1.1.2'
4
+ VERSION = '2.0.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.1.2
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: 2015-11-10 00:00:00.000000000 Z
11
+ date: 2016-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape