Sha256: 84cee0ab0643eaa4ae235b71ffac9de9535c1cdb3d6bc964e374bfdbdcbd8b3c
Contents?: true
Size: 1.67 KB
Versions: 16
Compression:
Stored size: 1.67 KB
Contents
# frozen_string_literal: true module Torque module PostgreSQL # = Torque PostgreSQL Railtie class Railtie < Rails::Railtie # :nodoc: # Get information from the running rails app initializer 'torque-postgresql' do |app| torque_config = Torque::PostgreSQL.config torque_config.eager_load = app.config.eager_load # Include enum on ActiveRecord::Base so it can have the correct enum # initializer Torque::PostgreSQL::Attributes::Enum.include_on(ActiveRecord::Base) Torque::PostgreSQL::Attributes::EnumSet.include_on(ActiveRecord::Base) Torque::PostgreSQL::Attributes::Period.include_on(ActiveRecord::Base) # Setup belongs_to_many association ActiveRecord::Base.belongs_to_many_required_by_default = torque_config.associations .belongs_to_many_required_by_default # Define a method to find enumaerators based on the namespace torque_config.enum.namespace.define_singleton_method(:const_missing) do |name| Torque::PostgreSQL::Attributes::Enum.lookup(name) end # Define a helper method to get a sample value torque_config.enum.namespace.define_singleton_method(:sample) do |name| Torque::PostgreSQL::Attributes::Enum.lookup(name).sample end # Define the exposed constant for auxiliary statements if torque_config.auxiliary_statement.exposed_class.present? *ns, name = torque_config.auxiliary_statement.exposed_class.split('::') base = ns.present? ? Object.const_get(ns.join('::')) : Object base.const_set(name, Torque::PostgreSQL::AuxiliaryStatement) end end end end end
Version data entries
16 entries across 16 versions & 1 rubygems