Sha256: 6c122b5a97246731c9fbffd99159dc39a2cad59c02aa235f6873711118d7ca57

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

require "multi_config/version"

# Module for this gem
module MultiConfig
  # Checking if Rails::Railtie exists. Only then loca this railtie
  if defined? Rails::Railtie
    require 'rails'
    # Railtie class for the gem. Initialization magic happens here. Inherits from Rails::Railtie so that initializer
    # methods are available to it
    class Railtie < Rails::Railtie
      # Railtie initializer method
      initializer 'multi_config.active_record' do
        # When active_record is loaded, only then run this. See method documentation to learn mode
        ActiveSupport.on_load :active_record do
          # Notice that full namespace is not given since search for Railtie class begin from this Module itself.
          Railtie.insert
        end
      end
    end
  end

  class Railtie
    # Include the module MultiConfig::ORMs::ActiveRecord in ActiveRecord::Base class
    def self.insert
      # Even though ActiveSupport called this method only when ActiveRecord was loaded. We are just being extra safe.
      if defined?(ActiveRecord)
        require 'multi_config/orms/active_record'
        # Calling private method :include via send. This is typically used in extensions to include a module.
        ActiveRecord::Base.send(:include, MultiConfig::ORMs::ActiveRecord)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
multi_config-1.0.0 lib/multi_config.rb
multi_config-0.2.2 lib/multi_config.rb
multi_config-0.2.0 lib/multi_config.rb
multi_config-0.1.9 lib/multi_config.rb
multi_config-0.1.8 lib/multi_config.rb