grape-activerecord 2.1.0 → 2.2.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: 0d4ebcdc246743c4619c07e314e4db8552433f42
4
- data.tar.gz: fee817f385ea83bc205c46dd07f7d91ae43aa0bf
3
+ metadata.gz: dda6f32c7861757fc813a1a09390b99fb0354606
4
+ data.tar.gz: cc923f413df377a6f44c82fa7fc9fbc6a5d1d08d
5
5
  SHA512:
6
- metadata.gz: 1e88f06e2b181780f1d5ccd1847496a806079574bd37e7de641d2fa34f4ff60b9b244f953f100dc03f9ed5a69957b73971ee25c9e7bd13b3de6893a0f7cb2561
7
- data.tar.gz: aeb141d99831ffe715b4db460fd1e4e3dc3b7fa7f828a85672717da695d2ee8ef1ce82fed5d6986699bf367d3314cbfd2eb0e91e2b9be42135f86976c18f8e7e
6
+ metadata.gz: e4463aec84606f0dd2f2b4455f3c845b97e10c9d3204ad5a5d4fe6475883574645ecc16070a61a7fd718e65c39bb30cd56179af42bc4af0b0c257973a15b6915
7
+ data.tar.gz: a477c9daa699ab0cbfd7b3378bfa905f199f903b269c0f4ea9c09876ff808e668ba2444ec684604c693fc87be520a59ba7fefff8ecdd774d9c88def1b0ef7551
data/README.md CHANGED
@@ -1,66 +1,3 @@
1
1
  # grape-activerecord
2
2
 
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. Supports:
4
-
5
- * ActiveRecord 4
6
- * ActiveRecord 5 (new, possibly buggy; please submit a PR if you find something!)
7
-
8
- ## How to use
9
-
10
- #### 1. Add it to your Gemfile
11
-
12
- gem "grape-activerecord"
13
-
14
- #### 2. Configure your database connection
15
-
16
- After loading your gems, tell `Grape::ActiveRecord` about your database config using one of the following examples:
17
-
18
- Grape::ActiveRecord.configure_from_file! "config/database.yml"
19
- Grape::ActiveRecord.configure_from_url! ENV['DATABASE_URL'] # e.g. postgres://user:pass@host/db
20
- Grape::ActiveRecord.configure_from_hash!(adapter: "postgresql", host: "localhost", database: "db", username: "user", password: "pass", encoding: "utf8", pool: 10, timeout: 5000)
21
-
22
- **Important note**: `configure_from_file!` won't work as expected if you have already `DATABASE_URL` set as part of your environment variables.
23
- This is because in ActiveRecord when that env variable is set it will merge its properties into the current connection configuration.
24
-
25
- #### 3. Enable ActiveRecord connection management
26
-
27
- This ActiveRecord middleware cleans up your database connections after each request. Add it to your `config.ru` file:
28
-
29
- use ActiveRecord::ConnectionAdapters::ConnectionManagement
30
-
31
- #### 4. Import ActiveRecord tasks into your Rakefile
32
-
33
- This will give you most of the standard `db:` tasks you get in Rails. Add it to your `Rakefile`.
34
-
35
- require "bundler/setup"
36
- load "tasks/grape-activerecord.rake"
37
-
38
- namespace :db do
39
- # Some db tasks require your app code to be loaded, or at least your gems
40
- task :environment do
41
- require_relative "app"
42
- end
43
- end
44
-
45
- Unlike in Rails, creating a new migration is also a rake task. Run `bundle exec rake -T` to get a full list.
46
-
47
- bundle exec rake db:create_migration NAME=create_widgets
48
-
49
- ## Examples
50
-
51
- Look under /example for an example app.
52
-
53
- ## Advanced options
54
-
55
- 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`:
56
-
57
- Grape::ActiveRecord.db_dir = 'db'
58
- Grape::ActiveRecord.migrations_paths = ['db/migrate']
59
- Grape::ActiveRecord.fixtures_path = 'test/fixtures'
60
- Grape::ActiveRecord.seed_file = 'seeds.rb'
61
-
62
- ## License
63
-
64
- Licensed under the MIT License
65
-
66
- Copyright 2014 Jordan Hollinger
3
+ **Moved to [otr-activerecord](https://github.com/jhollinger/otr-activerecord)**
@@ -1,7 +1,6 @@
1
- require 'active_record'
2
- require 'hashie-forbidden_attributes'
3
- require 'grape/activerecord/version'
4
- require 'grape/activerecord/activerecord'
5
- require 'grape/activerecord/compatibility_4'
6
- require 'grape/activerecord/compatibility_5'
7
- require 'grape/activerecord/defaults'
1
+ # Shim for otr-activerecord
2
+ require 'otr-activerecord'
3
+ module Grape
4
+ ActiveRecord = OTR::ActiveRecord
5
+ end
6
+ $stderr.puts "WARNING: grape-activerecord is deprecated; please switch to otr-activerecord"
@@ -1,91 +1 @@
1
- require 'pathname'
2
- require 'fileutils'
3
- require 'active_support/core_ext/string/strip'
4
- require 'active_support/core_ext/string/inflections'
5
- require 'grape/activerecord'
6
- load 'active_record/railties/databases.rake'
7
-
8
- #
9
- # Configure and override the default activerecord db rake tasks
10
- #
11
-
12
- Rake::Task.define_task('db:_load_config') do
13
- ::ActiveRecord::Base.logger = nil
14
- ::ActiveRecord::Tasks::DatabaseTasks.tap do |config|
15
- config.root = Rake.application.original_dir
16
- config.env = Grape::ActiveRecord.rack_env.to_s
17
- config.db_dir = Grape::ActiveRecord.db_dir
18
- config.migrations_paths = Array(Grape::ActiveRecord.migrations_paths)
19
- config.fixtures_path = Grape::ActiveRecord.fixtures_path
20
- config.database_configuration = ::ActiveRecord::Base.configurations
21
- config.seed_loader = Object.new
22
- config.seed_loader.instance_eval do
23
- def load_seed
24
- load "#{Grape::ActiveRecord.db_dir}/#{Grape::ActiveRecord.seed_file}"
25
- end
26
- end
27
- end
28
- end
29
-
30
- Rake::Task['db:load_config'].clear
31
- Rake::Task.define_task('db:load_config') do
32
- # Run the user's db:environment task first, so they have an opportunity to set a custom db config location
33
- Rake::Task['db:environment'].invoke
34
- end
35
-
36
- Rake::Task.define_task('db:environment') do
37
- # defined by user
38
- end
39
-
40
- # Load db config at the end of user-defined db:environment
41
- Rake::Task['db:environment'].enhance do
42
- Rake::Task['db:_load_config'].invoke
43
- end
44
-
45
- Rake::Task['db:test:deprecated'].clear if Rake::Task.task_defined?('db:test:deprecated')
46
-
47
- #
48
- # Define grape-activerecord helper tasks
49
- #
50
-
51
- namespace :db do
52
- namespace :test do
53
- task :environment do
54
- ENV['RACK_ENV'] = 'test'
55
- end
56
- end
57
-
58
- desc "Create a migration (parameters: NAME, VERSION)"
59
- task :create_migration do
60
- unless ENV["NAME"]
61
- puts "No NAME specified. Example usage: `rake db:create_migration NAME=create_widgets`"
62
- exit 1
63
- end
64
-
65
- name = ENV["NAME"]
66
- version = ENV["VERSION"] || Time.now.utc.strftime("%Y%m%d%H%M%S")
67
-
68
- Grape::ActiveRecord._normalizer.migrations_paths.each do |directory|
69
- next unless File.exists?(directory)
70
- migration_files = Pathname(directory).children
71
- if duplicate = migration_files.find { |path| path.basename.to_s.include?(name) }
72
- puts "Another migration is already named \"#{name}\": #{duplicate}."
73
- exit 1
74
- end
75
- end
76
-
77
- filename = "#{version}_#{name}.rb"
78
- dirname = Grape::ActiveRecord._normalizer.migrations_path
79
- path = File.join(dirname, filename)
80
-
81
- FileUtils.mkdir_p(dirname)
82
- File.write path, <<-MIGRATION.strip_heredoc
83
- class #{name.camelize} < #{Grape::ActiveRecord._normalizer.migration_base_class_name}
84
- def change
85
- end
86
- end
87
- MIGRATION
88
-
89
- puts path
90
- end
91
- end
1
+ load 'tasks/otr-activerecord.rake'
metadata CHANGED
@@ -1,64 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.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: 2016-07-31 00:00:00.000000000 Z
11
+ date: 2016-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: grape
14
+ name: otr-activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.1'
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.1'
27
- - !ruby/object:Gem::Dependency
28
- name: activerecord
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '4.0'
34
- - - "<="
35
- - !ruby/object:Gem::Version
36
- version: '5.0'
37
- type: :runtime
38
- prerelease: false
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: '4.0'
44
- - - "<="
45
- - !ruby/object:Gem::Version
46
- version: '5.0'
47
- - !ruby/object:Gem::Dependency
48
- name: hashie-forbidden_attributes
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '0.1'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '0.1'
61
- description: Extends Grape with simple ActiveRecord integration
26
+ version: '1.0'
27
+ description: Extends Grape with simple ActiveRecord integration. MOVED TO otr-activerecord.
62
28
  email: jordan.hollinger@gmail.com
63
29
  executables: []
64
30
  extensions: []
@@ -67,18 +33,18 @@ files:
67
33
  - LICENSE
68
34
  - README.md
69
35
  - lib/grape/activerecord.rb
70
- - lib/grape/activerecord/activerecord.rb
71
- - lib/grape/activerecord/compatibility_4.rb
72
- - lib/grape/activerecord/compatibility_5.rb
73
- - lib/grape/activerecord/defaults.rb
74
- - lib/grape/activerecord/rake.rb
75
- - lib/grape/activerecord/version.rb
76
36
  - lib/tasks/grape-activerecord.rake
77
37
  homepage: https://github.com/jhollinger/grape-activerecord
78
38
  licenses:
79
39
  - MIT
80
40
  metadata: {}
81
- post_install_message:
41
+ post_install_message: |
42
+ #
43
+ # DEPRECATION WARNING
44
+ # 'grape-activerecord' has been deprecated; 'otr-activerecord' has been installed instead.
45
+ # Please refer to the documentation for 'otr-activerecord' available at https://github.com/jhollinger/otr-activerecord
46
+ # Don't worry; it's nearly identical.
47
+ #
82
48
  rdoc_options: []
83
49
  require_paths:
84
50
  - lib
@@ -97,6 +63,6 @@ rubyforge_project:
97
63
  rubygems_version: 2.4.5.1
98
64
  signing_key:
99
65
  specification_version: 4
100
- summary: ActiveRecord integration for Grape
66
+ summary: ActiveRecord integration for Grape. MOVED TO otr-activerecord.
101
67
  test_files: []
102
68
  has_rdoc:
@@ -1,44 +0,0 @@
1
- require 'erb'
2
-
3
- # Grape and ActiveRecord integration
4
- module Grape
5
- # Grape and ActiveRecord integration
6
- module ActiveRecord
7
- class << self
8
- # Relative path to the "db" dir
9
- attr_accessor :db_dir
10
- # Relative path(s) to the migrations directory
11
- attr_accessor :migrations_paths
12
- # Relative path to the fixtures directory
13
- attr_accessor :fixtures_path
14
- # Name of the seeds file in db_dir
15
- attr_accessor :seed_file
16
- # Internal compatibility layer across different major versions of AR
17
- attr_accessor :_normalizer
18
- end
19
-
20
- # Connect to database with a Hash. Example:
21
- # {adapter: 'postgresql', host: 'localhost', database: 'db', username: 'user', password: 'pass', encoding: 'utf8', pool: 10, timeout: 5000}
22
- def self.configure_from_hash!(spec)
23
- ::ActiveRecord::Base.configurations = {rack_env => spec}.stringify_keys
24
- ::ActiveRecord::Base.establish_connection(rack_env)
25
- end
26
-
27
- # Connect to database with a DB URL. Example: "postgres://user:pass@localhost/db"
28
- def self.configure_from_url!(url)
29
- configure_from_hash! ::ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver.new(url).to_hash
30
- end
31
-
32
- # Connect to database with a yml file. Example: "config/database.yml"
33
- def self.configure_from_file!(path)
34
- raise "#{path} does not exist!" unless File.file? path
35
- ::ActiveRecord::Base.configurations = YAML.load(ERB.new(File.read(path)).result) || {}
36
- ::ActiveRecord::Base.establish_connection(rack_env)
37
- end
38
-
39
- # The current Rack environment
40
- def self.rack_env
41
- (ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development').to_sym
42
- end
43
- end
44
- end
@@ -1,30 +0,0 @@
1
- module Grape
2
- module ActiveRecord
3
- # Compatibility layer for ActiveRecord 4
4
- class Compatibility4
5
- attr_reader :major_version
6
-
7
- # Compatibility layer for ActiveRecord 4
8
- def initialize
9
- @major_version = 4
10
- ::ActiveRecord::Base.default_timezone = :utc
11
- ::ActiveRecord::Base.logger = Logger.new(STDOUT)
12
- end
13
-
14
- # All db migration dir paths
15
- def migrations_paths
16
- OTR::ActiveRecord.migrations_paths
17
- end
18
-
19
- # The dir in which to put new migrations
20
- def migrations_path
21
- OTR::ActiveRecord.migrations_paths[0]
22
- end
23
-
24
- # Basename of migration classes
25
- def migration_base_class_name
26
- 'ActiveRecord::Migration'
27
- end
28
- end
29
- end
30
- end
@@ -1,30 +0,0 @@
1
- module Grape
2
- module ActiveRecord
3
- # Compatibility layer for ActiveRecord 5
4
- class Compatibility5
5
- attr_reader :major_version
6
-
7
- # Compatibility layer for ActiveRecord 5
8
- def initialize
9
- @major_version = 5
10
- ::ActiveRecord::Base.default_timezone = :utc
11
- ::ActiveRecord::Base.logger = Logger.new(STDOUT)
12
- end
13
-
14
- # All db migration dir paths
15
- def migrations_paths
16
- OTR::ActiveRecord.migrations_paths
17
- end
18
-
19
- # The dir in which to put new migrations
20
- def migrations_path
21
- OTR::ActiveRecord.migrations_paths[0]
22
- end
23
-
24
- # Basename of migration classes
25
- def migration_base_class_name
26
- 'ActiveRecord::Migration[5.0]'
27
- end
28
- end
29
- end
30
- end
@@ -1,8 +0,0 @@
1
- Grape::ActiveRecord.db_dir = 'db'
2
- Grape::ActiveRecord.migrations_paths = %w(db/migrate)
3
- Grape::ActiveRecord.fixtures_path = 'test/fixtures'
4
- Grape::ActiveRecord.seed_file = 'seeds.rb'
5
- Grape::ActiveRecord._normalizer = case ::ActiveRecord::VERSION::MAJOR
6
- when 4 then Grape::ActiveRecord::Compatibility4.new
7
- when 5 then Grape::ActiveRecord::Compatibility5.new
8
- end
@@ -1,2 +0,0 @@
1
- $stderr.puts "WARNING: loading 'grape/activerecord/rake' in your Rakefile is deprecated; do 'load \"tasks/grape-activerecord.rake\"' instead"
2
- load "tasks/grape-activerecord.rake"
@@ -1,6 +0,0 @@
1
- module Grape
2
- module ActiveRecord
3
- # Gem version
4
- VERSION = '2.1.0'
5
- end
6
- end