From cba70a37d97e4276c73097a112d2a07964d558a4 Mon Sep 17 00:00:00 2001 From: Teo Ljungberg Date: Sat, 25 May 2024 19:04:27 +0200 Subject: [PATCH 1/3] Simplify Fx.load --- lib/fx.rb | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/lib/fx.rb b/lib/fx.rb index bcf5a5d..1bbbac2 100644 --- a/lib/fx.rb +++ b/lib/fx.rb @@ -19,20 +19,13 @@ module Fx # Enables fx migration methods, migration reversability, and `schema.rb` # dumping. def self.load - ActiveRecord::Migration::CommandRecorder.send( - :include, - Fx::CommandRecorder - ) - - ActiveRecord::SchemaDumper.send( - :prepend, - Fx::SchemaDumper - ) - - ActiveRecord::ConnectionAdapters::AbstractAdapter.send( - :include, - Fx::Statements - ) + { + ActiveRecord::Migration::CommandRecorder => Fx::CommandRecorder, + ActiveRecord::SchemaDumper => Fx::SchemaDumper, + ActiveRecord::ConnectionAdapters::AbstractAdapter => Fx::Statements, + }.each do |klass, mod| + klass.send(:include, mod) + end end # @return [Fx::Configuration] F(x)'s current configuration From c1e71f76732adeda4681d0a396cf904067c5154f Mon Sep 17 00:00:00 2001 From: Teo Ljungberg Date: Sun, 26 May 2024 10:36:49 +0200 Subject: [PATCH 2/3] Simplify 2 --- lib/fx.rb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/fx.rb b/lib/fx.rb index 1bbbac2..969ceb6 100644 --- a/lib/fx.rb +++ b/lib/fx.rb @@ -19,12 +19,24 @@ module Fx # Enables fx migration methods, migration reversability, and `schema.rb` # dumping. def self.load - { - ActiveRecord::Migration::CommandRecorder => Fx::CommandRecorder, - ActiveRecord::SchemaDumper => Fx::SchemaDumper, - ActiveRecord::ConnectionAdapters::AbstractAdapter => Fx::Statements, - }.each do |klass, mod| - klass.send(:include, mod) + [ + { + active_record_module: ActiveRecord::Migration::CommandRecorder, + fx_module: Fx::CommandRecorder, + action: :include, + }, + { + active_record_module: ActiveRecord::SchemaDumper, + fx_module: Fx::SchemaDumper, + action: :prepend, + }, + { + active_record_module: ActiveRecord::ConnectionAdapters::AbstractAdapter, + fx_module: Fx::Statements, + action: :include, + }, + ].each do |hook| + hook[:active_record_module].send(hook[:action], hook[:fx_module]) end end From 2f101f7ed317edd594999dc9db2df33ebf8081e2 Mon Sep 17 00:00:00 2001 From: Teo Ljungberg Date: Sun, 26 May 2024 10:39:06 +0200 Subject: [PATCH 3/3] Simplest of all --- lib/fx.rb | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/lib/fx.rb b/lib/fx.rb index 969ceb6..86976c2 100644 --- a/lib/fx.rb +++ b/lib/fx.rb @@ -19,25 +19,9 @@ module Fx # Enables fx migration methods, migration reversability, and `schema.rb` # dumping. def self.load - [ - { - active_record_module: ActiveRecord::Migration::CommandRecorder, - fx_module: Fx::CommandRecorder, - action: :include, - }, - { - active_record_module: ActiveRecord::SchemaDumper, - fx_module: Fx::SchemaDumper, - action: :prepend, - }, - { - active_record_module: ActiveRecord::ConnectionAdapters::AbstractAdapter, - fx_module: Fx::Statements, - action: :include, - }, - ].each do |hook| - hook[:active_record_module].send(hook[:action], hook[:fx_module]) - end + ActiveRecord::Migration::CommandRecorder.include(Fx::CommandRecorder) + ActiveRecord::ConnectionAdapters::AbstractAdapter.include(Fx::Statements) + ActiveRecord::SchemaDumper.prepend(Fx::SchemaDumper) end # @return [Fx::Configuration] F(x)'s current configuration