pax_global_header00006660000000000000000000000064141346652100014514gustar00rootroot0000000000000052 comment=b707e856124e5429871f07e61cf932da03380921 otr-activerecord-2.0.3/000077500000000000000000000000001413466521000147725ustar00rootroot00000000000000otr-activerecord-2.0.3/.gitignore000066400000000000000000000000661413466521000167640ustar00rootroot00000000000000/*.gem /Gemfile.lock /examples/**/*.sqlite3 .DS_Store otr-activerecord-2.0.3/.rspec000066400000000000000000000000261413466521000161050ustar00rootroot00000000000000--require spec_helper otr-activerecord-2.0.3/CHANGELOG.md000066400000000000000000000026421413466521000166070ustar00rootroot00000000000000### 2.0.3 (2021-10-22) * Preliminary support for ActiveRecord 7 (tested against 7.0.0.alpha2) ### 2.0.2 (2021-09-14) * Fix `configure_from_file!` for flat files (Brynbayliss87) ### 2.0.1 (2021-06-24) * Fix configure_from_url! for AR 6.1 ### 2.0.0 (2021-05-06) * Parse three-tier database.yml * Require manually calling OTR::ActiveRecord::establish_connection! ### 1.4.2 (2021-04-03) * Allow AR 6.1 ### 1.4.0 (2019-06-05) * Add `OTR::ActiveRecord::QueryCache` middleware. ### 1.3.0 * Active Record 6.0 support ### 1.2.7 (2019-01-11) * A less hacky way of fixing the bug fixed in 1.2.6. `ENV["RACK_ENV"]`/`ENV["RAILS_ENV"]` will no longer be forced into `development` when blank. ### 1.2.6 (2018-12-11) * Bugfix to default env in development mode w/AR 5.2 ### 1.2.5 (2018-04-23) * Support ActiveRecord 5.2 ### 1.2.4 (2017-08-23) * Bugfix to db:create_migration ### 1.2.3 (2017-08-17) * Bugfix to OTR::ActiveRecord.configure_from_hash! for ActiveRecord 5.1 * Look for APP_ENV if RAILS_ENV and RACK_ENV aren't set ### 1.2.2 (2017-08-17) * Support ActiveRecord 5.1 ### 1.2.1 (2017-02-11) * Bugfix to db:test: Rake tasks for Rails 5 ### 1.2.0 (2016-08-24) * Bugfix to AR 5.0.X version restriction - [PR #2](https://github.com/jhollinger/otr-activerecord/pull/2) - [vidok](https://github.com/vidok) ### 1.0.0-rc1 (2016-07-31) * Port from grape-activerecord * Tweak `db:create_migration` to take a real rake arg rather than an env var otr-activerecord-2.0.3/Gemfile000066400000000000000000000001361413466521000162650ustar00rootroot00000000000000 source 'https://rubygems.org' gemspec gem 'activerecord', '>6.0' gem 'rspec' gem 'sqlite3' otr-activerecord-2.0.3/LICENSE000066400000000000000000000020441413466521000157770ustar00rootroot00000000000000Copyright (c) 2016 Jordan Hollinger Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. otr-activerecord-2.0.3/README.md000066400000000000000000000060331413466521000162530ustar00rootroot00000000000000# otr-activerecord An easy way to use ActiveRecord "off the rails." Works with Grape, Sinatra, plain old Rack, or even in a boring little script!. The defaults are all very Railsy (`config/database.yml`, `db/seeds.rb`, `db/migrate`, etc.), but you can easily change them. (Formerly known as `grape-activerecord`.) Supports: * ActiveRecord 7.0.0.alpha2 (new AR features, like encryption, not tested) * ActiveRecord 6 * ActiveRecord 5 * ActiveRecord 4 ## How to use #### 1. Add it to your Gemfile gem "otr-activerecord" #### 2. Configure your database connection After loading your gems, tell `OTR::ActiveRecord` about your database config using one of the following examples: OTR::ActiveRecord.configure_from_file! "config/database.yml" OTR::ActiveRecord.configure_from_url! ENV['DATABASE_URL'] # e.g. postgres://user:pass@host/db OTR::ActiveRecord.configure_from_hash!(adapter: "postgresql", host: "localhost", database: "db", username: "user", password: "pass", encoding: "utf8", pool: 10, timeout: 5000) **Important note**: `configure_from_file!` won't work as expected if you have already `DATABASE_URL` set as part of your environment variables. This is because in ActiveRecord when that env variable is set it will merge its properties into the current connection configuration. #### 3. Connect to your database(s) If you have a single database (most apps), use this helper: OTR::ActiveRecord.establish_connection! If you're using multiple databases, call your base class(es) instead: MyBase.establish_connection :primary MyBase.establish_connection :primary_replica ... #### 4. Enable middleware for Rack apps Add these middlewares in `config.ru`: # Clean up database connections after every request (required) use OTR::ActiveRecord::ConnectionManagement # Enable ActiveRecord's QueryCache for every request (optional) use OTR::ActiveRecord::QueryCache #### 5. Import ActiveRecord tasks into your Rakefile This will give you most of the standard `db:` tasks you get in Rails. Add it to your `Rakefile`. require "bundler/setup" load "tasks/otr-activerecord.rake" namespace :db do # Some db tasks require your app code to be loaded; they'll expect to find it here task :environment do require_relative "app" end end Unlike in Rails, creating a new migration is also a rake task. Run `bundle exec rake -T` to get a full list of tasks. bundle exec rake db:create_migration[create_widgets] ## Examples Look under [/examples](https://github.com/jhollinger/otr-activerecord/tree/master/examples) for some example apps. ## Advanced options 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`: OTR::ActiveRecord.db_dir = 'db' OTR::ActiveRecord.migrations_paths = ['db/migrate'] OTR::ActiveRecord.fixtures_path = 'test/fixtures' OTR::ActiveRecord.seed_file = 'seeds.rb' ## License Licensed under the MIT License Copyright 2016 Jordan Hollinger otr-activerecord-2.0.3/Rakefile000066400000000000000000000000631413466521000164360ustar00rootroot00000000000000require 'bundler' Bundler::GemHelper.install_tasks otr-activerecord-2.0.3/examples/000077500000000000000000000000001413466521000166105ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/000077500000000000000000000000001413466521000224425ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/.gitignore000066400000000000000000000000271413466521000244310ustar00rootroot00000000000000/.bundle /db/*.sqlite3 otr-activerecord-2.0.3/examples/grape-activerecord4/Gemfile000066400000000000000000000005421413466521000237360ustar00rootroot00000000000000source 'https://rubygems.org' gem 'rack', '~> 1.6.0' gem 'grape', '~> 1.2.2' gem 'grape-entity', '~> 0.5.1' gem 'activerecord', '~> 4.2.7', require: 'active_record' gem 'otr-activerecord', '~> 1.1.0' gem 'sqlite3' gem 'rake' group :development do gem 'shotgun' end group :test do gem 'rack-test', require: 'rack/test' gem 'database_cleaner' end otr-activerecord-2.0.3/examples/grape-activerecord4/Gemfile.lock000066400000000000000000000036421413466521000246710ustar00rootroot00000000000000GEM remote: https://rubygems.org/ specs: activemodel (4.2.7) activesupport (= 4.2.7) builder (~> 3.1) activerecord (4.2.7) activemodel (= 4.2.7) activesupport (= 4.2.7) arel (~> 6.0) activesupport (4.2.7) i18n (~> 0.7) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) arel (6.0.3) axiom-types (0.1.1) descendants_tracker (~> 0.0.4) ice_nine (~> 0.11.0) thread_safe (~> 0.3, >= 0.3.1) builder (3.2.2) coercible (1.0.0) descendants_tracker (~> 0.0.1) database_cleaner (1.5.1) descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) equalizer (0.0.11) grape (1.2.2) activesupport builder mustermann-grape (~> 1.0.0) rack (>= 1.3.0) rack-accept virtus (>= 1.0.0) grape-entity (0.5.1) activesupport multi_json (>= 1.3.2) hashie (3.4.4) hashie-forbidden_attributes (0.1.1) hashie (>= 3.0) i18n (0.7.0) ice_nine (0.11.2) json (1.8.6) minitest (5.9.0) multi_json (1.12.1) mustermann (1.0.3) mustermann-grape (1.0.0) mustermann (~> 1.0.0) otr-activerecord (1.1.0) activerecord (>= 4.0, <= 5.0) hashie-forbidden_attributes (~> 0.1) rack (1.6.4) rack-accept (0.4.5) rack (>= 0.4) rack-test (0.6.3) rack (>= 1.0) rake (10.5.0) shotgun (0.9.1) rack (>= 1.0) sqlite3 (1.3.11) thread_safe (0.3.5) tzinfo (1.2.2) thread_safe (~> 0.1) virtus (1.0.5) axiom-types (~> 0.1) coercible (~> 1.0) descendants_tracker (~> 0.0, >= 0.0.3) equalizer (~> 0.0, >= 0.0.9) PLATFORMS ruby DEPENDENCIES activerecord (~> 4.2.7) database_cleaner grape (~> 1.2.2) grape-entity (~> 0.5.1) otr-activerecord (~> 1.1.0) rack (~> 1.6.0) rack-test rake shotgun sqlite3 BUNDLED WITH 2.0.1 otr-activerecord-2.0.3/examples/grape-activerecord4/Rakefile000066400000000000000000000007051413466521000241110ustar00rootroot00000000000000require 'bundler/setup' require 'rake/testtask' load 'tasks/otr-activerecord.rake' #OTR::ActiveRecord.db_dir = 'db' #OTR::ActiveRecord.migrations_paths = ['db/migrate'] #OTR::ActiveRecord.fixtures_path = 'test/fixtures' #OTR::ActiveRecord.seed_file = 'seeds.rb' namespace :db do task :environment do require_relative 'config/application' end end Rake::TestTask.new do |t| t.libs << 'test' t.test_files = FileList['test/**/*_test.rb'] end otr-activerecord-2.0.3/examples/grape-activerecord4/app/000077500000000000000000000000001413466521000232225ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/app/entities/000077500000000000000000000000001413466521000250465ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/app/entities/v1/000077500000000000000000000000001413466521000253745ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/app/entities/v1/widget.rb000066400000000000000000000003141413466521000272020ustar00rootroot00000000000000module Entities module V1 class Widget < Grape::Entity expose :id, documentation: {type: 'integer'} expose :name, documentation: {type: 'integer', desc: "Widget name"} end end end otr-activerecord-2.0.3/examples/grape-activerecord4/app/models/000077500000000000000000000000001413466521000245055ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/app/models/widget.rb000066400000000000000000000000461413466521000263150ustar00rootroot00000000000000class Widget < ActiveRecord::Base end otr-activerecord-2.0.3/examples/grape-activerecord4/app/routes/000077500000000000000000000000001413466521000245435ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/app/routes/v1.rb000066400000000000000000000002161413466521000254150ustar00rootroot00000000000000module Routes module V1 class API < Grape::API version 'v1' format :json mount Routes::V1::Widgets end end end otr-activerecord-2.0.3/examples/grape-activerecord4/app/routes/v1/000077500000000000000000000000001413466521000250715ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/app/routes/v1/widgets.rb000066400000000000000000000003051413466521000270620ustar00rootroot00000000000000module Routes module V1 class Widgets < Grape::API desc "Get a list of Widgets" get :widgets do present Widget.all, with: Entities::V1::Widget end end end end otr-activerecord-2.0.3/examples/grape-activerecord4/config.ru000066400000000000000000000002271413466521000242600ustar00rootroot00000000000000require './config/application' use OTR::ActiveRecord::ConnectionManagement run Rack::Cascade.new([ Routes::V1::API, # add versions as desired ]) otr-activerecord-2.0.3/examples/grape-activerecord4/config/000077500000000000000000000000001413466521000237075ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/config/application.rb000066400000000000000000000006571413466521000265470ustar00rootroot00000000000000require './config/environment' $:.unshift Config.root.join('lib') # Connect to database OTR::ActiveRecord.configure_from_file! Config.root.join('config', 'database.yml') OTR::ActiveRecord.establish_connection! # Load application [ %w(app models ** *.rb), %w(app entities ** *.rb), %w(app routes v* *.rb), %w(app routes ** *.rb), ].each do |pattern| Dir.glob(Config.root.join(*pattern)).each { |file| require file } end otr-activerecord-2.0.3/examples/grape-activerecord4/config/database.yml000066400000000000000000000004741413466521000262030ustar00rootroot00000000000000development: adapter: sqlite3 encoding: utf8 database: db/development.sqlite3 pool: 5 timeout: 5000 test: adapter: sqlite3 encoding: utf8 database: db/test.sqlite3 pool: 5 timeout: 5000 production: adapter: sqlite3 encoding: utf8 database: db/production.sqlite3 pool: 5 timeout: 5000 otr-activerecord-2.0.3/examples/grape-activerecord4/config/environment.rb000066400000000000000000000004541413466521000266030ustar00rootroot00000000000000require 'ostruct' require 'pathname' # Load environment settings Config = OpenStruct.new Config.env = ENV['RACK_ENV'] ? ENV['RACK_ENV'].to_sym : :development Config.root = Pathname.new(File.expand_path('../..', __FILE__)) # Load dependencies require 'bundler' Bundler.require(:default, Config.env) otr-activerecord-2.0.3/examples/grape-activerecord4/db/000077500000000000000000000000001413466521000230275ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/db/migrate/000077500000000000000000000000001413466521000244575ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/db/migrate/20140913065838_create_widgets.rb000066400000000000000000000002571413466521000314620ustar00rootroot00000000000000class CreateWidgets < ActiveRecord::Migration def change create_table :widgets do |t| t.string :name, null: false t.timestamps null: false end end end otr-activerecord-2.0.3/examples/grape-activerecord4/db/schema.rb000066400000000000000000000017251413466521000246210ustar00rootroot00000000000000# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your # database schema. If you need to create the application database on another # system, you should be using db:schema:load, not running all the migrations # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 20140913065838) do create_table "widgets", force: :cascade do |t| t.string "name", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end end otr-activerecord-2.0.3/examples/grape-activerecord4/db/seeds.rb000066400000000000000000000001131413466521000244520ustar00rootroot00000000000000Widget.create! name: 'A' Widget.create! name: 'B' Widget.create! name: 'C' otr-activerecord-2.0.3/examples/grape-activerecord4/lib/000077500000000000000000000000001413466521000232105ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/lib/.keep000066400000000000000000000000001413466521000241230ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/test/000077500000000000000000000000001413466521000234215ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/test/fixtures/000077500000000000000000000000001413466521000252725ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/test/fixtures/widgets.yml000066400000000000000000000001301413466521000274550ustar00rootroot00000000000000a: name: Widget A created_at: 2016-02-05 00:00:00 updated_at: 2016-02-05 00:00:00 otr-activerecord-2.0.3/examples/grape-activerecord4/test/models/000077500000000000000000000000001413466521000247045ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/test/models/widgets_test.rb000066400000000000000000000002511413466521000277340ustar00rootroot00000000000000require_relative '../test_helper' class WidgetsTest < TestCase def test_update widget = widgets(:a) widget.name = 'Widget B' assert widget.save end end otr-activerecord-2.0.3/examples/grape-activerecord4/test/routes/000077500000000000000000000000001413466521000247425ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/test/routes/v1/000077500000000000000000000000001413466521000252705ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/test/routes/v1/widgets_test.rb000066400000000000000000000002531413466521000303220ustar00rootroot00000000000000require_relative '../../test_helper' class ApiV1WidgestTest < ApiV1TestCase def test_get_widgets get '/v1/widgets' assert_equal 1, json_response.size end end otr-activerecord-2.0.3/examples/grape-activerecord4/test/support/000077500000000000000000000000001413466521000251355ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord4/test/support/api_test_case.rb000066400000000000000000000004371413466521000302710ustar00rootroot00000000000000require_relative './test_case' class ApiV1TestCase < TestCase include Rack::Test::Methods include ApiTestHelpers def app Routes::V1::API end end class ApiV2TestCase < TestCase include Rack::Test::Methods include ApiTestHelpers def app Routes::V1::AP2 end end otr-activerecord-2.0.3/examples/grape-activerecord4/test/support/helpers.rb000066400000000000000000000001561413466521000271260ustar00rootroot00000000000000module ApiTestHelpers def json_response JSON.parse(last_response.body, symbolize_names: true) end end otr-activerecord-2.0.3/examples/grape-activerecord4/test/support/test_case.rb000066400000000000000000000010271413466521000274340ustar00rootroot00000000000000require_relative './helpers' class TestCase < Minitest::Test def setup DatabaseCleaner.start end def teardown DatabaseCleaner.clean end fixture_names = Dir.glob('./test/fixtures/*.yml').map { |path| File.basename(path).sub(/\.yml$/, '') } fixtures = ActiveRecord::FixtureSet.create_fixtures('test/fixtures', fixture_names) fixtures.each do |fixture_set| define_method fixture_set.name do |record_name| id = fixture_set[record_name.to_s]['id'] fixture_set.model_class.find(id) end end end otr-activerecord-2.0.3/examples/grape-activerecord4/test/test_helper.rb000066400000000000000000000004571413466521000262720ustar00rootroot00000000000000ENV['RACK_ENV'] = 'test' require 'minitest/autorun' require_relative '../config/application' require 'active_record/fixtures' ActiveRecord::Base.logger = nil ActiveRecord::Migration.verbose = false DatabaseCleaner.strategy = :transaction Dir.glob('./test/support/*.rb').each { |file| require file } otr-activerecord-2.0.3/examples/grape-activerecord5/000077500000000000000000000000001413466521000224435ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/.gitignore000066400000000000000000000000351413466521000244310ustar00rootroot00000000000000/.bundle /database/*.sqlite3 otr-activerecord-2.0.3/examples/grape-activerecord5/Gemfile000066400000000000000000000005421413466521000237370ustar00rootroot00000000000000source 'https://rubygems.org' gem 'rack', '~> 1.6.0' gem 'grape', '~> 1.2.2' gem 'grape-entity', '~> 0.5.1' gem 'activerecord', '~> 5.0.2', require: 'active_record' gem 'otr-activerecord', '~> 1.2.1' gem 'sqlite3' gem 'rake' group :development do gem 'shotgun' end group :test do gem 'rack-test', require: 'rack/test' gem 'database_cleaner' end otr-activerecord-2.0.3/examples/grape-activerecord5/Gemfile.lock000066400000000000000000000035751413466521000246770ustar00rootroot00000000000000GEM remote: https://rubygems.org/ specs: activemodel (5.0.2) activesupport (= 5.0.2) activerecord (5.0.2) activemodel (= 5.0.2) activesupport (= 5.0.2) arel (~> 7.0) activesupport (5.0.2) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) arel (7.1.4) axiom-types (0.1.1) descendants_tracker (~> 0.0.4) ice_nine (~> 0.11.0) thread_safe (~> 0.3, >= 0.3.1) builder (3.2.3) coercible (1.0.0) descendants_tracker (~> 0.0.1) concurrent-ruby (1.0.5) database_cleaner (1.5.1) descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) equalizer (0.0.11) grape (1.2.2) activesupport builder mustermann-grape (~> 1.0.0) rack (>= 1.3.0) rack-accept virtus (>= 1.0.0) grape-entity (0.5.1) activesupport multi_json (>= 1.3.2) hashie (3.5.5) hashie-forbidden_attributes (0.1.1) hashie (>= 3.0) i18n (0.8.1) ice_nine (0.11.2) minitest (5.10.1) multi_json (1.12.1) mustermann (1.0.3) mustermann-grape (1.0.0) mustermann (~> 1.0.0) otr-activerecord (1.2.1) activerecord (>= 4.0, < 5.1) hashie-forbidden_attributes (~> 0.1) rack (1.6.4) rack-accept (0.4.5) rack (>= 0.4) rack-test (0.6.3) rack (>= 1.0) rake (10.5.0) shotgun (0.9.1) rack (>= 1.0) sqlite3 (1.3.11) thread_safe (0.3.6) tzinfo (1.2.3) thread_safe (~> 0.1) virtus (1.0.5) axiom-types (~> 0.1) coercible (~> 1.0) descendants_tracker (~> 0.0, >= 0.0.3) equalizer (~> 0.0, >= 0.0.9) PLATFORMS ruby DEPENDENCIES activerecord (~> 5.0.2) database_cleaner grape (~> 1.2.2) grape-entity (~> 0.5.1) otr-activerecord (~> 1.2.1) rack (~> 1.6.0) rack-test rake shotgun sqlite3 BUNDLED WITH 1.17.1 otr-activerecord-2.0.3/examples/grape-activerecord5/Rakefile000066400000000000000000000007201413466521000241070ustar00rootroot00000000000000require 'bundler/setup' require 'rake/testtask' load 'tasks/otr-activerecord.rake' OTR::ActiveRecord.db_dir = 'database' OTR::ActiveRecord.migrations_paths = ['database/migrations'] OTR::ActiveRecord.fixtures_path = 'test/fixtures' OTR::ActiveRecord.seed_file = 'seeds.rb' namespace :db do task :environment do require_relative 'config/application' end end Rake::TestTask.new do |t| t.libs << 'test' t.test_files = FileList['test/**/*_test.rb'] end otr-activerecord-2.0.3/examples/grape-activerecord5/app/000077500000000000000000000000001413466521000232235ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/app/entities/000077500000000000000000000000001413466521000250475ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/app/entities/v1/000077500000000000000000000000001413466521000253755ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/app/entities/v1/widget.rb000066400000000000000000000003141413466521000272030ustar00rootroot00000000000000module Entities module V1 class Widget < Grape::Entity expose :id, documentation: {type: 'integer'} expose :name, documentation: {type: 'integer', desc: "Widget name"} end end end otr-activerecord-2.0.3/examples/grape-activerecord5/app/models/000077500000000000000000000000001413466521000245065ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/app/models/widget.rb000066400000000000000000000000461413466521000263160ustar00rootroot00000000000000class Widget < ActiveRecord::Base end otr-activerecord-2.0.3/examples/grape-activerecord5/app/routes/000077500000000000000000000000001413466521000245445ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/app/routes/v1.rb000066400000000000000000000002161413466521000254160ustar00rootroot00000000000000module Routes module V1 class API < Grape::API version 'v1' format :json mount Routes::V1::Widgets end end end otr-activerecord-2.0.3/examples/grape-activerecord5/app/routes/v1/000077500000000000000000000000001413466521000250725ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/app/routes/v1/widgets.rb000066400000000000000000000003051413466521000270630ustar00rootroot00000000000000module Routes module V1 class Widgets < Grape::API desc "Get a list of Widgets" get :widgets do present Widget.all, with: Entities::V1::Widget end end end end otr-activerecord-2.0.3/examples/grape-activerecord5/config.ru000066400000000000000000000002271413466521000242610ustar00rootroot00000000000000require './config/application' use OTR::ActiveRecord::ConnectionManagement run Rack::Cascade.new([ Routes::V1::API, # add versions as desired ]) otr-activerecord-2.0.3/examples/grape-activerecord5/config/000077500000000000000000000000001413466521000237105ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/config/application.rb000066400000000000000000000006571413466521000265500ustar00rootroot00000000000000require './config/environment' $:.unshift Config.root.join('lib') # Connect to database OTR::ActiveRecord.configure_from_file! Config.root.join('config', 'database.yml') OTR::ActiveRecord.establish_connection! # Load application [ %w(app models ** *.rb), %w(app entities ** *.rb), %w(app routes v* *.rb), %w(app routes ** *.rb), ].each do |pattern| Dir.glob(Config.root.join(*pattern)).each { |file| require file } end otr-activerecord-2.0.3/examples/grape-activerecord5/config/database.yml000066400000000000000000000005161413466521000262010ustar00rootroot00000000000000development: adapter: sqlite3 encoding: utf8 database: database/development.sqlite3 pool: 5 timeout: 5000 test: adapter: sqlite3 encoding: utf8 database: database/test.sqlite3 pool: 5 timeout: 5000 production: adapter: sqlite3 encoding: utf8 database: database/production.sqlite3 pool: 5 timeout: 5000 otr-activerecord-2.0.3/examples/grape-activerecord5/config/environment.rb000066400000000000000000000004541413466521000266040ustar00rootroot00000000000000require 'ostruct' require 'pathname' # Load environment settings Config = OpenStruct.new Config.env = ENV['RACK_ENV'] ? ENV['RACK_ENV'].to_sym : :development Config.root = Pathname.new(File.expand_path('../..', __FILE__)) # Load dependencies require 'bundler' Bundler.require(:default, Config.env) otr-activerecord-2.0.3/examples/grape-activerecord5/database/000077500000000000000000000000001413466521000242075ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/database/migrations/000077500000000000000000000000001413466521000263635ustar00rootroot0000000000000020160730195332_create_widgets.rb000066400000000000000000000002641413466521000332750ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/database/migrationsclass CreateWidgets < ActiveRecord::Migration[5.0] def change create_table :widgets do |t| t.string :name, null: false t.timestamps null: false end end end otr-activerecord-2.0.3/examples/grape-activerecord5/database/schema.rb000066400000000000000000000017031413466521000257750ustar00rootroot00000000000000# This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your # database schema. If you need to create the application database on another # system, you should be using db:schema:load, not running all the migrations # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 20160730195332) do create_table "widgets", force: :cascade do |t| t.string "name", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end end otr-activerecord-2.0.3/examples/grape-activerecord5/database/seeds.rb000066400000000000000000000001131413466521000256320ustar00rootroot00000000000000Widget.create! name: 'A' Widget.create! name: 'B' Widget.create! name: 'C' otr-activerecord-2.0.3/examples/grape-activerecord5/lib/000077500000000000000000000000001413466521000232115ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/lib/.keep000066400000000000000000000000001413466521000241240ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/test/000077500000000000000000000000001413466521000234225ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/test/fixtures/000077500000000000000000000000001413466521000252735ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/test/fixtures/widgets.yml000066400000000000000000000001301413466521000274560ustar00rootroot00000000000000a: name: Widget A created_at: 2016-02-05 00:00:00 updated_at: 2016-02-05 00:00:00 otr-activerecord-2.0.3/examples/grape-activerecord5/test/models/000077500000000000000000000000001413466521000247055ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/test/models/widgets_test.rb000066400000000000000000000002511413466521000277350ustar00rootroot00000000000000require_relative '../test_helper' class WidgetsTest < TestCase def test_update widget = widgets(:a) widget.name = 'Widget B' assert widget.save end end otr-activerecord-2.0.3/examples/grape-activerecord5/test/routes/000077500000000000000000000000001413466521000247435ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/test/routes/v1/000077500000000000000000000000001413466521000252715ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/test/routes/v1/widgets_test.rb000066400000000000000000000002531413466521000303230ustar00rootroot00000000000000require_relative '../../test_helper' class ApiV1WidgestTest < ApiV1TestCase def test_get_widgets get '/v1/widgets' assert_equal 1, json_response.size end end otr-activerecord-2.0.3/examples/grape-activerecord5/test/support/000077500000000000000000000000001413466521000251365ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/grape-activerecord5/test/support/api_test_case.rb000066400000000000000000000004371413466521000302720ustar00rootroot00000000000000require_relative './test_case' class ApiV1TestCase < TestCase include Rack::Test::Methods include ApiTestHelpers def app Routes::V1::API end end class ApiV2TestCase < TestCase include Rack::Test::Methods include ApiTestHelpers def app Routes::V1::AP2 end end otr-activerecord-2.0.3/examples/grape-activerecord5/test/support/helpers.rb000066400000000000000000000001561413466521000271270ustar00rootroot00000000000000module ApiTestHelpers def json_response JSON.parse(last_response.body, symbolize_names: true) end end otr-activerecord-2.0.3/examples/grape-activerecord5/test/support/test_case.rb000066400000000000000000000010271413466521000274350ustar00rootroot00000000000000require_relative './helpers' class TestCase < Minitest::Test def setup DatabaseCleaner.start end def teardown DatabaseCleaner.clean end fixture_names = Dir.glob('./test/fixtures/*.yml').map { |path| File.basename(path).sub(/\.yml$/, '') } fixtures = ActiveRecord::FixtureSet.create_fixtures('test/fixtures', fixture_names) fixtures.each do |fixture_set| define_method fixture_set.name do |record_name| id = fixture_set[record_name.to_s]['id'] fixture_set.model_class.find(id) end end end otr-activerecord-2.0.3/examples/grape-activerecord5/test/test_helper.rb000066400000000000000000000004571413466521000262730ustar00rootroot00000000000000ENV['RACK_ENV'] = 'test' require 'minitest/autorun' require_relative '../config/application' require 'active_record/fixtures' ActiveRecord::Base.logger = nil ActiveRecord::Migration.verbose = false DatabaseCleaner.strategy = :transaction Dir.glob('./test/support/*.rb').each { |file| require file } otr-activerecord-2.0.3/examples/rakefile-activerecord5.2/000077500000000000000000000000001413466521000232675ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/rakefile-activerecord5.2/.gitignore000066400000000000000000000000311413466521000252510ustar00rootroot00000000000000/.bundle /data/*.sqlite3 otr-activerecord-2.0.3/examples/rakefile-activerecord5.2/Gemfile000066400000000000000000000002231413466521000245570ustar00rootroot00000000000000source 'https://rubygems.org' gem 'activerecord', '~> 5.2.0', require: 'active_record' gem 'otr-activerecord', path: '../../' gem 'pg' gem 'rake' otr-activerecord-2.0.3/examples/rakefile-activerecord5.2/Gemfile.lock000066400000000000000000000015721413466521000255160ustar00rootroot00000000000000PATH remote: ../.. specs: otr-activerecord (1.3.1) activerecord (>= 4.0, < 6.1) hashie-forbidden_attributes (~> 0.1) GEM remote: https://rubygems.org/ specs: activemodel (5.2.3) activesupport (= 5.2.3) activerecord (5.2.3) activemodel (= 5.2.3) activesupport (= 5.2.3) arel (>= 9.0) activesupport (5.2.3) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) arel (9.0.0) concurrent-ruby (1.1.5) hashie (3.6.0) hashie-forbidden_attributes (0.1.1) hashie (>= 3.0) i18n (1.6.0) concurrent-ruby (~> 1.0) minitest (5.11.3) pg (1.1.4) rake (12.3.2) thread_safe (0.3.6) tzinfo (1.2.5) thread_safe (~> 0.1) PLATFORMS ruby DEPENDENCIES activerecord (~> 5.2.0) otr-activerecord! pg rake BUNDLED WITH 2.0.1 otr-activerecord-2.0.3/examples/rakefile-activerecord5.2/Rakefile000066400000000000000000000023241413466521000247350ustar00rootroot00000000000000require 'bundler/setup' load 'tasks/otr-activerecord.rake' OTR::ActiveRecord.db_dir = 'data' OTR::ActiveRecord.migrations_paths = ['data/migrate'] OTR::ActiveRecord.seed_file = 'seeds.rb' namespace :db do task :environment do require_relative 'environment' end end namespace :widgets do desc "Query all widgets" task :query => 'db:environment' do widgets = Widget.order('name').to_a puts widgets.map(&:as_json).to_json end desc "Fetch a single widget" task :fetch, [:id] => 'db:environment' do |_, args| widget = Widget.find(args[:id]) puts widget.to_json end desc "Create a new widget" task :create, [:name] => 'db:environment' do |_, args| widget = Widget.new(name: args[:name]) if widget.save puts widget.to_json else abort({errors: widget.errors.full_message}.to_json) end end desc "Update a widget" task :update, [:id, :name] => 'db:environment' do |_, args| widget = Widget.where(id: args[:id]).first abort({errors: ["Widget '#{args[:id]}' not found"]}.to_json) if widget.nil? if widget.update_attributes({name: args[:name]}) puts widget.to_json else abort({errors: widget.errors.full_message}.to_json) end end end otr-activerecord-2.0.3/examples/rakefile-activerecord5.2/data/000077500000000000000000000000001413466521000242005ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/rakefile-activerecord5.2/data/config.yml000066400000000000000000000005031413466521000261660ustar00rootroot00000000000000development: adapter: postgresql encoding: utf8 database: otr_example_52_dev pool: 5 timeout: 5000 test: adapter: postgresql encoding: utf8 database: otr_example_52_test pool: 5 timeout: 5000 production: adapter: postgresql encoding: utf8 database: otr_example_52_prod pool: 5 timeout: 5000 otr-activerecord-2.0.3/examples/rakefile-activerecord5.2/data/migrate/000077500000000000000000000000001413466521000256305ustar00rootroot0000000000000020160731142314_create_widgets.rb000066400000000000000000000002641413466521000325330ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/rakefile-activerecord5.2/data/migrateclass CreateWidgets < ActiveRecord::Migration[5.0] def change create_table :widgets do |t| t.string :name, null: false t.timestamps null: false end end end 20171128231939_create_splines.rb000066400000000000000000000003011413466521000325500ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/rakefile-activerecord5.2/data/migrateclass CreateSplines < ActiveRecord::Migration[5.2] def change create_table :splines do |t| t.string :name, null: false end add_index :splines, :name, unique: true end end otr-activerecord-2.0.3/examples/rakefile-activerecord5.2/data/migrate/20180423164820_foo.rb000066400000000000000000000002101413466521000304010ustar00rootroot00000000000000class Foo < ActiveRecord::Migration[5.2] def change create_table :foos do |t| t.string :name, null: false end end end otr-activerecord-2.0.3/examples/rakefile-activerecord5.2/data/schema.rb000066400000000000000000000024351413466521000257710ustar00rootroot00000000000000# This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your # database schema. If you need to create the application database on another # system, you should be using db:schema:load, not running all the migrations # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2018_04_23_164820) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" create_table "foos", force: :cascade do |t| t.string "name", null: false end create_table "splines", force: :cascade do |t| t.string "name", null: false t.index ["name"], name: "index_splines_on_name", unique: true end create_table "widgets", force: :cascade do |t| t.string "name", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end end otr-activerecord-2.0.3/examples/rakefile-activerecord5.2/data/seeds.rb000066400000000000000000000001131413466521000256230ustar00rootroot00000000000000Widget.create! name: 'A' Widget.create! name: 'B' Widget.create! name: 'C' otr-activerecord-2.0.3/examples/rakefile-activerecord5.2/environment.rb000066400000000000000000000011001413466521000261500ustar00rootroot00000000000000require 'json' require 'bundler' Bundler.require(:default, ENV['OTR_ENV'] ? ENV['OTR_ENV'].to_sym : :development) OTR::ActiveRecord.configure_from_file! './data/config.yml' #OTR::ActiveRecord.configure_from_url! 'sqlite3:///home/jhollinger/devel/otr-activerecord/examples/rakefile-activerecord5.2/db.sqlite3' #OTR::ActiveRecord.configure_from_hash!(adapter: 'sqlite3', database: '/home/jhollinger/devel/otr-activerecord/examples/rakefile-activerecord5.2/db.sqlite3') OTR::ActiveRecord.establish_connection! class Widget < ActiveRecord::Base validates_presence_of :name end otr-activerecord-2.0.3/examples/rakefile-activerecord5/000077500000000000000000000000001413466521000231275ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/rakefile-activerecord5/.gitignore000066400000000000000000000000311413466521000251110ustar00rootroot00000000000000/.bundle /data/*.sqlite3 otr-activerecord-2.0.3/examples/rakefile-activerecord5/Gemfile000066400000000000000000000002241413466521000244200ustar00rootroot00000000000000source 'https://rubygems.org' gem 'activerecord', '~> 5.0.0', require: 'active_record' gem 'otr-activerecord', '~> 1.1.0' gem 'sqlite3' gem 'rake' otr-activerecord-2.0.3/examples/rakefile-activerecord5/Gemfile.lock000066400000000000000000000015141413466521000253520ustar00rootroot00000000000000GEM remote: https://rubygems.org/ specs: activemodel (5.0.0) activesupport (= 5.0.0) activerecord (5.0.0) activemodel (= 5.0.0) activesupport (= 5.0.0) arel (~> 7.0) activesupport (5.0.0) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) arel (7.1.1) concurrent-ruby (1.0.2) hashie (3.4.4) hashie-forbidden_attributes (0.1.1) hashie (>= 3.0) i18n (0.7.0) minitest (5.9.0) otr-activerecord (1.1.0) activerecord (>= 4.0, <= 5.0) hashie-forbidden_attributes (~> 0.1) rake (11.2.2) sqlite3 (1.3.11) thread_safe (0.3.5) tzinfo (1.2.2) thread_safe (~> 0.1) PLATFORMS ruby DEPENDENCIES activerecord (~> 5.0.0) otr-activerecord (~> 1.1.0) rake sqlite3 BUNDLED WITH 2.0.1 otr-activerecord-2.0.3/examples/rakefile-activerecord5/Rakefile000066400000000000000000000022071413466521000245750ustar00rootroot00000000000000require 'bundler/setup' load 'tasks/otr-activerecord.rake' OTR::ActiveRecord.db_dir = 'data' OTR::ActiveRecord.migrations_paths = ['data/migrate'] OTR::ActiveRecord.seed_file = 'seeds.rb' namespace :db do task :environment do require_relative 'environment' end end namespace :widgets do desc "Query all widgets" task :query => 'db:environment' do widgets = Widget.order('name').to_a puts widgets.map(&:as_json).to_json end desc "Fetch a single widget" task :fetch => 'db:environment' do end desc "Create a new widget" task :create, [:name] => 'db:environment' do |_, args| widget = Widget.new(name: args[:name]) if widget.save puts widget.to_json else abort({errors: widget.errors.full_message}.to_json) end end desc "Update a widget" task :update, [:id, :name] => 'db:environment' do |_, args| widget = Widget.where(id: args[:id]).first abort({errors: ["Widget '#{args[:id]}' not found"]}.to_json) if widget.nil? if widget.update_attributes({name: args[:name]}) puts widget.to_json else abort({errors: widget.errors.full_message}.to_json) end end end otr-activerecord-2.0.3/examples/rakefile-activerecord5/data/000077500000000000000000000000001413466521000240405ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/rakefile-activerecord5/data/config.yml000066400000000000000000000005021413466521000260250ustar00rootroot00000000000000development: adapter: sqlite3 encoding: utf8 database: data/development.sqlite3 pool: 5 timeout: 5000 test: adapter: sqlite3 encoding: utf8 database: data/test.sqlite3 pool: 5 timeout: 5000 production: adapter: sqlite3 encoding: utf8 database: data/production.sqlite3 pool: 5 timeout: 5000 otr-activerecord-2.0.3/examples/rakefile-activerecord5/data/migrate/000077500000000000000000000000001413466521000254705ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/rakefile-activerecord5/data/migrate/20160731142314_create_widgets.rb000066400000000000000000000002641413466521000324520ustar00rootroot00000000000000class CreateWidgets < ActiveRecord::Migration[5.0] def change create_table :widgets do |t| t.string :name, null: false t.timestamps null: false end end end otr-activerecord-2.0.3/examples/rakefile-activerecord5/data/schema.rb000066400000000000000000000017031413466521000256260ustar00rootroot00000000000000# This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your # database schema. If you need to create the application database on another # system, you should be using db:schema:load, not running all the migrations # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 20160731142314) do create_table "widgets", force: :cascade do |t| t.string "name", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end end otr-activerecord-2.0.3/examples/rakefile-activerecord5/data/seeds.rb000066400000000000000000000001131413466521000254630ustar00rootroot00000000000000Widget.create! name: 'A' Widget.create! name: 'B' Widget.create! name: 'C' otr-activerecord-2.0.3/examples/rakefile-activerecord5/environment.rb000066400000000000000000000004321413466521000260170ustar00rootroot00000000000000require 'json' require 'bundler' Bundler.require(:default, ENV['OTR_ENV'] ? ENV['OTR_ENV'].to_sym : :development) OTR::ActiveRecord.configure_from_file! './data/config.yml' OTR::ActiveRecord.establish_connection! class Widget < ActiveRecord::Base validates_presence_of :name end otr-activerecord-2.0.3/examples/rakefile-activerecord6.0/000077500000000000000000000000001413466521000232665ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/rakefile-activerecord6.0/.gitignore000066400000000000000000000000311413466521000252500ustar00rootroot00000000000000/.bundle /data/*.sqlite3 otr-activerecord-2.0.3/examples/rakefile-activerecord6.0/Gemfile000066400000000000000000000002301413466521000245540ustar00rootroot00000000000000source 'https://rubygems.org' gem 'activerecord', '~> 6.0.0', require: 'active_record' gem 'otr-activerecord', path: '../../' gem 'sqlite3' gem 'rake' otr-activerecord-2.0.3/examples/rakefile-activerecord6.0/Gemfile.lock000066400000000000000000000016701413466521000255140ustar00rootroot00000000000000PATH remote: ../.. specs: otr-activerecord (2.0.1) activerecord (>= 4.0, < 6.3) hashie-forbidden_attributes (~> 0.1) GEM remote: https://rubygems.org/ specs: activemodel (6.0.3.5) activesupport (= 6.0.3.5) activerecord (6.0.3.5) activemodel (= 6.0.3.5) activesupport (= 6.0.3.5) activesupport (6.0.3.5) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) zeitwerk (~> 2.2, >= 2.2.2) concurrent-ruby (1.1.8) hashie (4.1.0) hashie-forbidden_attributes (0.1.1) hashie (>= 3.0) i18n (1.8.8) concurrent-ruby (~> 1.0) minitest (5.14.3) rake (12.3.2) sqlite3 (1.4.2) thread_safe (0.3.6) tzinfo (1.2.9) thread_safe (~> 0.1) zeitwerk (2.4.2) PLATFORMS ruby universal-darwin-20 DEPENDENCIES activerecord (~> 6.0.0) otr-activerecord! rake sqlite3 BUNDLED WITH 2.2.1 otr-activerecord-2.0.3/examples/rakefile-activerecord6.0/Rakefile000066400000000000000000000023211413466521000247310ustar00rootroot00000000000000require 'bundler/setup' load 'tasks/otr-activerecord.rake' OTR::ActiveRecord.db_dir = 'data' OTR::ActiveRecord.migrations_paths = ['data/migrate'] OTR::ActiveRecord.seed_file = 'seeds.rb' namespace :db do task :environment do require_relative 'environment' end end namespace :widgets do desc "Query all widgets" task :query => 'db:environment' do widgets = Widget.order('name').to_a puts widgets.map(&:as_json).to_json end desc "Fetch a single widget" task :fetch, [:id] => 'db:environment' do |_, args| widget = Widget.find(args[:id]) puts widget.to_json end desc "Create a new widget" task :create, [:name] => 'db:environment' do |_, args| widget = Widget.new(name: args[:name]) if widget.save puts widget.to_json else abort({errors: widget.errors.full_message}.to_json) end end desc "Update a widget" task :update, [:id, :name] => 'db:environment' do |_, args| widget = Widget.where(id: args[:id]).first abort({errors: ["Widget '#{args[:id]}' not found"]}.to_json) if widget.nil? if widget.update_columns({name: args[:name]}) puts widget.to_json else abort({errors: widget.errors.full_message}.to_json) end end end otr-activerecord-2.0.3/examples/rakefile-activerecord6.0/data/000077500000000000000000000000001413466521000241775ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/rakefile-activerecord6.0/data/config.yml000066400000000000000000000005411413466521000261670ustar00rootroot00000000000000development: adapter: sqlite3 encoding: utf8 database: data/otr_example_60_dev.sqlite3 pool: 5 timeout: 5000 test: adapter: sqlite3 encoding: utf8 database: data/otr_example_60_test.sqlite3 pool: 5 timeout: 5000 production: adapter: sqlite3 encoding: utf8 database: data/otr_example_60_prod.sqlite3 pool: 5 timeout: 5000 otr-activerecord-2.0.3/examples/rakefile-activerecord6.0/data/migrate/000077500000000000000000000000001413466521000256275ustar00rootroot0000000000000020160731142314_create_widgets.rb000066400000000000000000000002641413466521000325320ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/rakefile-activerecord6.0/data/migrateclass CreateWidgets < ActiveRecord::Migration[5.0] def change create_table :widgets do |t| t.string :name, null: false t.timestamps null: false end end end 20171128231939_create_splines.rb000066400000000000000000000003011413466521000325470ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/rakefile-activerecord6.0/data/migrateclass CreateSplines < ActiveRecord::Migration[5.2] def change create_table :splines do |t| t.string :name, null: false end add_index :splines, :name, unique: true end end otr-activerecord-2.0.3/examples/rakefile-activerecord6.0/data/migrate/20180423164820_foo.rb000066400000000000000000000002101413466521000304000ustar00rootroot00000000000000class Foo < ActiveRecord::Migration[5.2] def change create_table :foos do |t| t.string :name, null: false end end end otr-activerecord-2.0.3/examples/rakefile-activerecord6.0/data/schema.rb000066400000000000000000000024351413466521000257700ustar00rootroot00000000000000# This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your # database schema. If you need to create the application database on another # system, you should be using db:schema:load, not running all the migrations # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2018_04_23_164820) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" create_table "foos", force: :cascade do |t| t.string "name", null: false end create_table "splines", force: :cascade do |t| t.string "name", null: false t.index ["name"], name: "index_splines_on_name", unique: true end create_table "widgets", force: :cascade do |t| t.string "name", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end end otr-activerecord-2.0.3/examples/rakefile-activerecord6.0/data/seeds.rb000066400000000000000000000001131413466521000256220ustar00rootroot00000000000000Widget.create! name: 'A' Widget.create! name: 'B' Widget.create! name: 'C' otr-activerecord-2.0.3/examples/rakefile-activerecord6.0/environment.rb000066400000000000000000000011001413466521000261470ustar00rootroot00000000000000require 'json' require 'bundler' Bundler.require(:default, ENV['OTR_ENV'] ? ENV['OTR_ENV'].to_sym : :development) OTR::ActiveRecord.configure_from_file! './data/config.yml' #OTR::ActiveRecord.configure_from_url! 'sqlite3:///home/jhollinger/devel/otr-activerecord/examples/rakefile-activerecord5.2/db.sqlite3' #OTR::ActiveRecord.configure_from_hash!(adapter: 'sqlite3', database: '/home/jhollinger/devel/otr-activerecord/examples/rakefile-activerecord5.2/db.sqlite3') OTR::ActiveRecord.establish_connection! class Widget < ActiveRecord::Base validates_presence_of :name end otr-activerecord-2.0.3/examples/rakefile-activerecord7.0/000077500000000000000000000000001413466521000232675ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/rakefile-activerecord7.0/.gitignore000066400000000000000000000000311413466521000252510ustar00rootroot00000000000000/.bundle /data/*.sqlite3 otr-activerecord-2.0.3/examples/rakefile-activerecord7.0/Gemfile000066400000000000000000000002341413466521000245610ustar00rootroot00000000000000source 'https://rubygems.org' gem 'activerecord', '7.0.0.alpha2', require: 'active_record' gem 'otr-activerecord', path: '../../' gem 'sqlite3' gem 'rake' otr-activerecord-2.0.3/examples/rakefile-activerecord7.0/Gemfile.lock000066400000000000000000000015741413466521000255200ustar00rootroot00000000000000PATH remote: ../.. specs: otr-activerecord (2.0.2) activerecord (>= 4.0, < 7.1) hashie-forbidden_attributes (~> 0.1) GEM remote: https://rubygems.org/ specs: activemodel (7.0.0.alpha2) activesupport (= 7.0.0.alpha2) activerecord (7.0.0.alpha2) activemodel (= 7.0.0.alpha2) activesupport (= 7.0.0.alpha2) activesupport (7.0.0.alpha2) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) concurrent-ruby (1.1.9) hashie (4.1.0) hashie-forbidden_attributes (0.1.1) hashie (>= 3.0) i18n (1.8.10) concurrent-ruby (~> 1.0) minitest (5.14.4) rake (13.0.6) sqlite3 (1.4.2) tzinfo (2.0.4) concurrent-ruby (~> 1.0) PLATFORMS ruby DEPENDENCIES activerecord (= 7.0.0.alpha2) otr-activerecord! rake sqlite3 BUNDLED WITH 2.1.4 otr-activerecord-2.0.3/examples/rakefile-activerecord7.0/Rakefile000066400000000000000000000023211413466521000247320ustar00rootroot00000000000000require 'bundler/setup' load 'tasks/otr-activerecord.rake' OTR::ActiveRecord.db_dir = 'data' OTR::ActiveRecord.migrations_paths = ['data/migrate'] OTR::ActiveRecord.seed_file = 'seeds.rb' namespace :db do task :environment do require_relative 'environment' end end namespace :widgets do desc "Query all widgets" task :query => 'db:environment' do widgets = Widget.order('name').to_a puts widgets.map(&:as_json).to_json end desc "Fetch a single widget" task :fetch, [:id] => 'db:environment' do |_, args| widget = Widget.find(args[:id]) puts widget.to_json end desc "Create a new widget" task :create, [:name] => 'db:environment' do |_, args| widget = Widget.new(name: args[:name]) if widget.save puts widget.to_json else abort({errors: widget.errors.full_message}.to_json) end end desc "Update a widget" task :update, [:id, :name] => 'db:environment' do |_, args| widget = Widget.where(id: args[:id]).first abort({errors: ["Widget '#{args[:id]}' not found"]}.to_json) if widget.nil? if widget.update_columns({name: args[:name]}) puts widget.to_json else abort({errors: widget.errors.full_message}.to_json) end end end otr-activerecord-2.0.3/examples/rakefile-activerecord7.0/data/000077500000000000000000000000001413466521000242005ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/rakefile-activerecord7.0/data/config.yml000066400000000000000000000005411413466521000261700ustar00rootroot00000000000000development: adapter: sqlite3 encoding: utf8 database: data/otr_example_70_dev.sqlite3 pool: 5 timeout: 5000 test: adapter: sqlite3 encoding: utf8 database: data/otr_example_70_test.sqlite3 pool: 5 timeout: 5000 production: adapter: sqlite3 encoding: utf8 database: data/otr_example_70_prod.sqlite3 pool: 5 timeout: 5000 otr-activerecord-2.0.3/examples/rakefile-activerecord7.0/data/migrate/000077500000000000000000000000001413466521000256305ustar00rootroot0000000000000020160731142314_create_widgets.rb000066400000000000000000000002641413466521000325330ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/rakefile-activerecord7.0/data/migrateclass CreateWidgets < ActiveRecord::Migration[5.0] def change create_table :widgets do |t| t.string :name, null: false t.timestamps null: false end end end 20171128231939_create_splines.rb000066400000000000000000000003011413466521000325500ustar00rootroot00000000000000otr-activerecord-2.0.3/examples/rakefile-activerecord7.0/data/migrateclass CreateSplines < ActiveRecord::Migration[5.2] def change create_table :splines do |t| t.string :name, null: false end add_index :splines, :name, unique: true end end otr-activerecord-2.0.3/examples/rakefile-activerecord7.0/data/migrate/20180423164820_foo.rb000066400000000000000000000002101413466521000304010ustar00rootroot00000000000000class Foo < ActiveRecord::Migration[5.2] def change create_table :foos do |t| t.string :name, null: false end end end otr-activerecord-2.0.3/examples/rakefile-activerecord7.0/data/migrate/20211023013351_bar.rb000066400000000000000000000002101413466521000303410ustar00rootroot00000000000000class Bar < ActiveRecord::Migration[7.0] def change create_table :bars do |t| t.string :name, null: false end end end otr-activerecord-2.0.3/examples/rakefile-activerecord7.0/data/schema.rb000066400000000000000000000024241413466521000257670ustar00rootroot00000000000000# This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # This file is the source Rails uses to define your schema when running `bin/rails # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to # be faster and is potentially less error prone than running all of your # migrations from scratch. Old migrations may fail to apply correctly if those # migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2021_10_23_013351) do create_table "bars", force: :cascade do |t| t.string "name", null: false end create_table "foos", force: :cascade do |t| t.string "name", null: false end create_table "splines", force: :cascade do |t| t.string "name", null: false t.index ["name"], name: "index_splines_on_name", unique: true end create_table "widgets", force: :cascade do |t| t.string "name", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false end end otr-activerecord-2.0.3/examples/rakefile-activerecord7.0/data/seeds.rb000066400000000000000000000001131413466521000256230ustar00rootroot00000000000000Widget.create! name: 'A' Widget.create! name: 'B' Widget.create! name: 'C' otr-activerecord-2.0.3/examples/rakefile-activerecord7.0/environment.rb000066400000000000000000000011001413466521000261500ustar00rootroot00000000000000require 'json' require 'bundler' Bundler.require(:default, ENV['OTR_ENV'] ? ENV['OTR_ENV'].to_sym : :development) OTR::ActiveRecord.configure_from_file! './data/config.yml' #OTR::ActiveRecord.configure_from_url! 'sqlite3:///home/jhollinger/devel/otr-activerecord/examples/rakefile-activerecord5.2/db.sqlite3' #OTR::ActiveRecord.configure_from_hash!(adapter: 'sqlite3', database: '/home/jhollinger/devel/otr-activerecord/examples/rakefile-activerecord5.2/db.sqlite3') OTR::ActiveRecord.establish_connection! class Widget < ActiveRecord::Base validates_presence_of :name end otr-activerecord-2.0.3/lib/000077500000000000000000000000001413466521000155405ustar00rootroot00000000000000otr-activerecord-2.0.3/lib/otr-activerecord.rb000066400000000000000000000004331413466521000213410ustar00rootroot00000000000000require 'active_record' require 'hashie-forbidden_attributes' require 'otr-activerecord/version' require 'otr-activerecord/activerecord' require 'otr-activerecord/middleware/connection_management' require 'otr-activerecord/middleware/query_cache' require 'otr-activerecord/defaults' otr-activerecord-2.0.3/lib/otr-activerecord/000077500000000000000000000000001413466521000210145ustar00rootroot00000000000000otr-activerecord-2.0.3/lib/otr-activerecord/activerecord.rb000066400000000000000000000062021413466521000240130ustar00rootroot00000000000000require 'erb' # "Off the Rails" ActiveRecord configuration/integration for Grape, Sinatra, Rack, and any other kind of app module OTR # ActiveRecord configuration module module ActiveRecord autoload :Compatibility4, 'otr-activerecord/compatibility_4' autoload :Compatibility5, 'otr-activerecord/compatibility_5' autoload :Compatibility6, 'otr-activerecord/compatibility_6' autoload :Compatibility7, 'otr-activerecord/compatibility_7' class << self # Relative path to the "db" dir attr_accessor :db_dir # Relative path(s) to the migrations directory attr_accessor :migrations_paths # Relative path to the fixtures directory attr_accessor :fixtures_path # Name of the seeds file in db_dir attr_accessor :seed_file # Internal compatibility layer across different major versions of AR attr_accessor :_normalizer end # Connect to database with a Hash. Example: # {adapter: 'postgresql', host: 'localhost', database: 'db', username: 'user', password: 'pass', encoding: 'utf8', pool: 10, timeout: 5000} def self.configure_from_hash!(spec) config = spec.stringify_keys.merge("migrations_paths" => ::OTR::ActiveRecord.migrations_paths) ::ActiveRecord::Base.configurations = {rack_env.to_s => config} end # Connect to database with a DB URL. Example: "postgres://user:pass@localhost/db" def self.configure_from_url!(url) require 'uri' uri = URI(url) spec = {"adapter" => uri.scheme} case spec["adapter"] when /^sqlite/i spec["database"] = url =~ /::memory:/ ? ":memory:" : "#{uri.host}#{uri.path}" else spec["host"] = uri.host if uri.host spec["port"] = uri.port if uri.port spec["database"] = uri.path.sub(/^\//, "") spec["username"] = uri.user if uri.user spec["password"] = uri.password if uri.password end if uri.query opts_ary = URI.decode_www_form(uri.query) opts = Hash[opts_ary] spec.merge!(opts) end configure_from_hash! spec end # Connect to database with a yml file. Example: "config/database.yml" def self.configure_from_file!(path) raise "#{path} does not exist!" unless File.file? path result =(YAML.safe_load(ERB.new(File.read(path)).result, [], [], true) || {}) ::ActiveRecord::Base.configurations = begin result.each do |_env, config| if config.all? { |_, v| v.is_a?(Hash) } config.each { |_, v| append_migration_path(v) } else append_migration_path(config) end end end end # Establish a connection to the given db (defaults to current rack env) def self.establish_connection!(db = rack_env) ::ActiveRecord::Base.establish_connection(db) end def self.append_migration_path(config) config['migrations_paths'] = ::OTR::ActiveRecord.migrations_paths unless config.key?('migrations_paths') config end # The current Rack environment def self.rack_env (ENV['RACK_ENV'] || ENV['RAILS_ENV'] || ENV['APP_ENV'] || ENV['OTR_ENV'] || 'development').to_sym end end end otr-activerecord-2.0.3/lib/otr-activerecord/compatibility_4.rb000066400000000000000000000015431413466521000244400ustar00rootroot00000000000000module OTR module ActiveRecord # Compatibility layer for ActiveRecord 4 class Compatibility4 attr_reader :major_version # Compatibility layer for ActiveRecord 4 def initialize @major_version = 4 ::ActiveRecord::Base.default_timezone = :utc ::ActiveRecord::Base.logger = Logger.new(STDOUT) end # All db migration dir paths def migrations_paths OTR::ActiveRecord.migrations_paths end # The dir in which to put new migrations def migrations_path OTR::ActiveRecord.migrations_paths[0] end # Basename of migration classes def migration_base_class_name 'ActiveRecord::Migration' end # Force RACK_ENV/RAILS_ENV to be 'test' when running any db:test:* tasks def force_db_test_env? true end end end end otr-activerecord-2.0.3/lib/otr-activerecord/compatibility_5.rb000066400000000000000000000016501413466521000244400ustar00rootroot00000000000000module OTR module ActiveRecord # Compatibility layer for ActiveRecord 5 class Compatibility5 attr_reader :major_version # Compatibility layer for ActiveRecord 5 def initialize @major_version = 5 ::ActiveRecord::Base.default_timezone = :utc ::ActiveRecord::Base.logger = Logger.new(STDOUT) end # All db migration dir paths def migrations_paths OTR::ActiveRecord.migrations_paths end # The dir in which to put new migrations def migrations_path OTR::ActiveRecord.migrations_paths[0] end # Basename of migration classes def migration_base_class_name version = "5.#{::ActiveRecord::VERSION::MINOR}" "ActiveRecord::Migration[#{version}]" end # Force RACK_ENV/RAILS_ENV to be 'test' when running any db:test:* tasks def force_db_test_env? false end end end end otr-activerecord-2.0.3/lib/otr-activerecord/compatibility_6.rb000066400000000000000000000016701413466521000244430ustar00rootroot00000000000000module OTR module ActiveRecord # Compatibility layer for ActiveRecord 6 class Compatibility6 attr_reader :major_version # Compatibility layer for ActiveRecord 6 def initialize @major_version = 6 ::ActiveRecord::Base.default_timezone = :utc ::ActiveRecord::Base.logger = Logger.new(STDOUT) end # All db migration dir paths def migrations_paths OTR::ActiveRecord.migrations_paths end # The dir in which to put new migrations def migrations_path OTR::ActiveRecord.migrations_paths[0] end # Basename of migration classes def migration_base_class_name version = "#{@major_version}.#{::ActiveRecord::VERSION::MINOR}" "ActiveRecord::Migration[#{version}]" end # Force RACK_ENV/RAILS_ENV to be 'test' when running any db:test:* tasks def force_db_test_env? false end end end end otr-activerecord-2.0.3/lib/otr-activerecord/compatibility_7.rb000066400000000000000000000004541413466521000244430ustar00rootroot00000000000000module OTR module ActiveRecord # Compatibility layer for ActiveRecord 7 class Compatibility7 < Compatibility6 def initialize @major_version = 7 ::ActiveRecord.default_timezone = :utc ::ActiveRecord::Base.logger = Logger.new(STDOUT) end end end end otr-activerecord-2.0.3/lib/otr-activerecord/defaults.rb000066400000000000000000000010011413466521000231400ustar00rootroot00000000000000ENV["DISABLE_DATABASE_ENVIRONMENT_CHECK"] ||= "true" OTR::ActiveRecord.db_dir = 'db' OTR::ActiveRecord.migrations_paths = %w(db/migrate) OTR::ActiveRecord.fixtures_path = 'test/fixtures' OTR::ActiveRecord.seed_file = 'seeds.rb' OTR::ActiveRecord._normalizer = case ::ActiveRecord::VERSION::MAJOR when 4 then OTR::ActiveRecord::Compatibility4.new when 5 then OTR::ActiveRecord::Compatibility5.new when 6 then OTR::ActiveRecord::Compatibility6.new when 7 then OTR::ActiveRecord::Compatibility7.new end otr-activerecord-2.0.3/lib/otr-activerecord/middleware/000077500000000000000000000000001413466521000231315ustar00rootroot00000000000000otr-activerecord-2.0.3/lib/otr-activerecord/middleware/connection_management.rb000066400000000000000000000011501413466521000300060ustar00rootroot00000000000000module OTR module ActiveRecord # # Rack middleware that returns active db connections to the connection pool after a request completes. # class ConnectionManagement def initialize(app) @app = app end def call(env) testing = env['rack.test'] == true resp = @app.call env resp[2] = ::Rack::BodyProxy.new resp[2] do ::ActiveRecord::Base.clear_active_connections! unless testing end resp rescue Exception ::ActiveRecord::Base.clear_active_connections! unless testing raise end end end end otr-activerecord-2.0.3/lib/otr-activerecord/middleware/query_cache.rb000066400000000000000000000014131413466521000257450ustar00rootroot00000000000000module OTR module ActiveRecord # # Rack middleware to enable ActiveRecord's query cache for each request. # class QueryCache def initialize(app) @handler = case ::ActiveRecord::VERSION::MAJOR when 4 then ::ActiveRecord::QueryCache.new(app) when 5, 6 then ActionDispatchHandler.new(app) end end def call(env) @handler.call(env) end class ActionDispatchHandler def initialize(app) @app = app end def call(env) state = nil state = ::ActiveRecord::QueryCache.run @app.call(env) ensure ::ActiveRecord::QueryCache.complete(state) if state end end end end end otr-activerecord-2.0.3/lib/otr-activerecord/version.rb000066400000000000000000000001231413466521000230220ustar00rootroot00000000000000module OTR module ActiveRecord # Gem version VERSION = '2.0.3' end end otr-activerecord-2.0.3/lib/tasks/000077500000000000000000000000001413466521000166655ustar00rootroot00000000000000otr-activerecord-2.0.3/lib/tasks/otr-activerecord.rake000066400000000000000000000050311413466521000230040ustar00rootroot00000000000000require 'pathname' require 'fileutils' require 'active_support/core_ext/string/strip' require 'active_support/core_ext/string/inflections' require 'otr-activerecord' load 'active_record/railties/databases.rake' # # Configure and override the default activerecord db rake tasks # Rake::Task.define_task('db:_load_config') do ::ActiveRecord::Base.logger = nil ::ActiveRecord::Tasks::DatabaseTasks.tap do |config| config.root = Rake.application.original_dir config.env = OTR::ActiveRecord.rack_env.to_s config.db_dir = OTR::ActiveRecord.db_dir config.migrations_paths = Array(OTR::ActiveRecord.migrations_paths) config.fixtures_path = OTR::ActiveRecord.fixtures_path config.database_configuration = ::ActiveRecord::Base.configurations config.seed_loader = Object.new config.seed_loader.instance_eval do def load_seed load "#{OTR::ActiveRecord.db_dir}/#{OTR::ActiveRecord.seed_file}" end end end end Rake::Task['db:load_config'].clear Rake::Task.define_task('db:load_config') do # Run the user's db:environment task first, so they have an opportunity to set a custom db config location Rake::Task['db:environment'].invoke end Rake::Task.define_task('db:environment') do # defined by user end # Load db config at the end of user-defined db:environment Rake::Task['db:environment'].enhance do Rake::Task['db:_load_config'].invoke end Rake::Task['db:test:deprecated'].clear if Rake::Task.task_defined?('db:test:deprecated') # # Define otr-activerecord helper tasks # namespace :db do namespace :test do task :environment do ENV['RACK_ENV'] = 'test' end end if OTR::ActiveRecord._normalizer.force_db_test_env? desc "Create a migration" task :create_migration, [:name] do |_, args| name, version = args[:name], Time.now.utc.strftime("%Y%m%d%H%M%S") OTR::ActiveRecord._normalizer.migrations_paths.each do |directory| next unless File.exists?(directory) migration_files = Pathname(directory).children if duplicate = migration_files.find { |path| path.basename.to_s.include?(name) } abort "Another migration is already named \"#{name}\": #{duplicate}." end end filename = "#{version}_#{name}.rb" dirname = OTR::ActiveRecord._normalizer.migrations_path path = File.join(dirname, filename) FileUtils.mkdir_p(dirname) File.write path, <<-MIGRATION.strip_heredoc class #{name.camelize} < #{OTR::ActiveRecord._normalizer.migration_base_class_name} def change end end MIGRATION puts path end end otr-activerecord-2.0.3/otr-activerecord.gemspec000066400000000000000000000015651413466521000216220ustar00rootroot00000000000000# encoding: utf-8 require File.expand_path('../lib/otr-activerecord/version.rb', __FILE__) Gem::Specification.new do |gem| gem.name = 'otr-activerecord' gem.version = OTR::ActiveRecord::VERSION gem.date = '2021-10-22' gem.description = 'Off The Rails ActiveRecord: Use ActiveRecord with Grape, Sinatra, Rack, or anything else! Formerly known as \'grape-activerecord\'.' gem.summary = 'Off The Rails: Use ActiveRecord with Grape, Sinatra, Rack, or anything else!' gem.homepage = 'https://github.com/jhollinger/otr-activerecord' gem.authors = ['Jordan Hollinger'] gem.email = 'jordan.hollinger@gmail.com' gem.license = 'MIT' gem.files = Dir['lib/**/**'] + ['README.md', 'LICENSE'] gem.required_ruby_version = '>= 2.1.0' gem.add_runtime_dependency 'activerecord', ['>= 4.0', '< 7.1'] gem.add_runtime_dependency 'hashie-forbidden_attributes', '~> 0.1' end otr-activerecord-2.0.3/spec/000077500000000000000000000000001413466521000157245ustar00rootroot00000000000000otr-activerecord-2.0.3/spec/fixtures/000077500000000000000000000000001413466521000175755ustar00rootroot00000000000000otr-activerecord-2.0.3/spec/fixtures/multi.yml000066400000000000000000000005141413466521000214520ustar00rootroot00000000000000.defaults: &defaults adapter: sqlite3 database: tmp/multi.sqlite3 development: primary: <<: *defaults reading: <<: *defaults replica: true production: primary: <<: *defaults reading: <<: *defaults replica: true test: primary: <<: *defaults reading: <<: *defaults replica: true otr-activerecord-2.0.3/spec/fixtures/simple.yml000066400000000000000000000002311413466521000216050ustar00rootroot00000000000000.defaults: &defaults adapter: sqlite3 database: tmp/simple.sqlite3 development: <<: *defaults production: <<: *defaults test: <<: *defaults otr-activerecord-2.0.3/spec/otr-activerecord/000077500000000000000000000000001413466521000212005ustar00rootroot00000000000000otr-activerecord-2.0.3/spec/otr-activerecord/activerecord_spec.rb000066400000000000000000000016711413466521000252160ustar00rootroot00000000000000RSpec.describe OTR::ActiveRecord do describe '.configure_from_file!' do context 'when simple configuration file is given' do let(:config) { Bundler.root.join('spec/fixtures/simple.yml') } it 'configures active record' do described_class.configure_from_file!(config) expect(::ActiveRecord::Base.configurations['test']).to eq( adapter: 'sqlite3', database: 'tmp/simple.sqlite3', migrations_paths: ['db/migrate'] ) end end context 'when configuration file with multiple roles given' do let(:config) { Bundler.root.join('spec/fixtures/multi.yml') } it 'configures active record' do described_class.configure_from_file!(config) expect(::ActiveRecord::Base.configurations['test']).to eq( adapter: 'sqlite3', database: 'tmp/multi.sqlite3', migrations_paths: ['db/migrate'] ) end end end end otr-activerecord-2.0.3/spec/spec_helper.rb000066400000000000000000000002171413466521000205420ustar00rootroot00000000000000require 'otr-activerecord' RSpec.configure do |config| config.color = true config.tty = true config.filter_run_when_matching :focus end