From b8476c72a4fa94d703e1b3fb6ea19a199ad70d45 Mon Sep 17 00:00:00 2001 From: Yanko Ivanov Date: Thu, 7 Mar 2024 07:56:59 +0200 Subject: [PATCH 1/2] Explicitly require active_record/railtie Requiring gem's entry point e.g. `require "monarch_migrate"` outside of a Rails application, raises an error: > uninitialized constant ActiveRecord (NameError) During development, we may want to start an IRB console session in the context of the gem. Requiring gem's entry point also loads a class that extends ActiveRecord::Base. However, in this context, ActiveRecord is not loaded. Explicitly requiring ActiveRecord's railtie in gem's entry point solves the problem. --- lib/monarch_migrate.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/monarch_migrate.rb b/lib/monarch_migrate.rb index ab18719..8ca948e 100644 --- a/lib/monarch_migrate.rb +++ b/lib/monarch_migrate.rb @@ -16,6 +16,7 @@ def self.migrator end require "rails" +require "active_record/railtie" require "monarch_migrate/migration" require "monarch_migrate/migration_record" require "monarch_migrate/migrator" From eba7812a598a0838e53236efc129881e23fb65ae Mon Sep 17 00:00:00 2001 From: Yanko Ivanov Date: Thu, 7 Mar 2024 09:40:43 +0200 Subject: [PATCH 2/2] Add bin/console script The script starts an IRB console session in the context of the gem. This is useful during development to test something quickly. No database operations will work out of the box, though. This is a future topic. --- bin/console | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 bin/console diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..10bddc2 --- /dev/null +++ b/bin/console @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby + +require "irb" +require "bundler/setup" +require_relative "../lib/monarch_migrate" + +binding.irb