Skip to content

Configuring

Carlos Silva edited this page Jul 29, 2025 · 20 revisions

Some resources may have extra configurations that can be set in your application.rb as follows:

# application.rb
Torque::PostgreSQL.configure do |c|
  c.enum.base_method = :pg_enum
end

Most features can now be enabled and disabled. For the most part, disabling will load fewer classes and changes into your application. If you decide not to use some of the available features, please disable them in your application, as most are enabled by default.

General configurations

These are the keys available to configure general features:

eager_load Set if any information that requires querying, searching, or collecting information should be eager loaded. This automatically changes when rails' same configuration is set to true.
Default value: false

irregular_models Set a list of irregular model names when associated with table names. It uses the 'table_name' => 'ModelName' format. This is widely used for inheritance because record types need to be associated with a model class.
Default value: {}

Associations configurations

These are the keys available to configure associations features:

associations.belongs_to_many_required_by_default Define if belongs_to_many associations are marked as required by default. false means that no validation will be performed.
Default value: false

Schemas configurations

These are the keys available to configure schemas features:

schemas.enabled Enables schemas handler by this gem, not Rails's implementation.
Default value: true

schemas.blacklist Defines a list of LIKE-based schemas to not consider for a multiple schema database. This is also available on config/database.yml as schemas and nested within it, blacklist.
Default value: ['information_schema ', 'pg_%']

schemas.whitelist Defines a list of LIKE-based schemas to consider for a multiple schema database. This is also available on config/database.yml as schemas and nested within it, whitelist.
Default value: ['public']

Auxiliary statements configurations

These are the keys available to configure Auxiliary statements features:

auxiliary_statement.enabled Enables auxiliary statements handler by this gem, not Rails's own implementation.
Default value: true

auxiliary_statement.send_arguments_key Define the key that is used on auxiliary statements to send extra arguments to format string or send on a proc.
Default value: :args

auxiliary_statement.exposed_class Estipulate a class name (which may contain namespace) that exposes the auxiliary statement in order to perform detached CTEs.
Default value: 'TorqueCTE'

auxiliary_statement.exposed_recursive_class Estipulate a class name (which may contain namespace) that exposes the recursive auxiliary statement in order to perform detached CTEs.
Default value: 'TorqueRecursiveCTE'

Enum configurations

These are the keys available to configure Enum features:

enum.enabled Enables enum handler by this gem, not Rails's implementation.
Default value: true

enum.base_method The name of the method to be used on any ActiveRecord::Base to initialize model-based enum features.
Default value: :torque_enum

enum.set_method The name of the method to be used on any ActiveRecord::Base to initialize model-based enum set features.
Default value: :torque_enum_set

enum.save_on_bang Indicates if bang methods like 'disabled!' should update the record in the database or not.
Default value: true

enum.raise_conflicting Indicates if it should raise errors when a generated method would conflict with an existing one.
Default value: false

enum.namespace Specify the namespace of each enum-type of value, such as ::Enum::Roles.
Default value: ::Enum

enum.i18n_scopes Specify the scopes for I18n translations.
Default value:

[ 'activerecord.attributes.%{model}.%{attr}.%{value}',
  'activerecord.attributes.%{attr}.%{value}',
  'activerecord.enums.%{type}.%{value}',
  'enum.%{type}.%{value}',
  'enum.%{value}' ]

enum.i18n_type_scope Specify the scopes for I18n translations, detached from model.
Default value: # Same list as before but without items that have ${attr} or %{model}

Geometry configurations

These are the keys available to configure geometry features:

geometry.enabled Enables geometry handler by this gem, not Rails's implementation.
Default value: true

geometry.point_class Define the class that will be handling Point data types after decoding it. Any class provided here must respond to 'x', and 'y'.
Default value: ActiveRecord::Point

geometry.box_class Define the class that will be handling Circle data types after decoding it. Any class provided here must respond to 'x', 'y', and 'r'.
Default value: nil # Which will define an internal Circle class

geometry.circle_class Define the class that will be handling Box data types after decoding it. Any class provided here must respond to 'x1', 'y1', 'x2', and 'y2'.
Default value: nil # Which will define an internal Box class

geometry.line_class Define the class that will be handling Line data types after decoding it. Any class provided here must respond to 'a', 'b', and 'c'.
Default value: nil # Which will define an internal Line class

geometry.segment_class Define the class that will be handling Segment data types after decoding it. Any class provided here must respond to 'x1', 'y1', 'x2', and 'y2'.
Default value: nil # Which will define an internal Segment class

Inheritance configurations

These are the keys available to configure Inheritance features:

inheritance.inverse_lookup Define the lookup of models from their given name to be inverted, which means that they are going to form the last namespaced one to the most namespaced one. If you prefer User::Role instead of UserRole as model name, set this to false to improve performance.
Default value: true

inheritance.record_class_column_name Determines the name of the column used to collect the table of each record. When the table has inheritance tables, this column will return the name of the table that actually holds the record.
Default value: :_record_class

inheritance.auto_cast_column_name Determines the name of the column used when identifying that the loaded records should be cast to their correct model. This will be TRUE for the records mentioned on cast_records.
Default value: :_auto_cast

Period configurations

These are the keys available to configure Period features:

period.enabled Enables period handler by this gem
Default value: true

period.base_method The name of the method to be used on any ActiveRecord::Base to initialize model-based period features.
Default value: :period_for

period.auto_threshold The default name for a threshold attribute, which will automatically enable threshold features.
Default value: :threshold

period.method_names Define the list of methods that will be created by default while setting up a new period field. Note that %s will be replaced by the name of the filter.
Default value:

{ current_on:            '%s_on',
  current:               'current_%s',
  not_current:           'not_current_%s',
  containing:            '%s_containing',
  not_containing:        '%s_not_containing',
  overlapping:           '%s_overlapping',
  not_overlapping:       '%s_not_overlapping',
  starting_after:        '%s_starting_after',
  starting_before:       '%s_starting_before',
  finishing_after:       '%s_finishing_after',
  finishing_before:      '%s_finishing_before',

  real_containing:       '%s_real_containing',
  real_overlapping:      '%s_real_overlapping',
  real_starting_after:   '%s_real_starting_after',
  real_starting_before:  '%s_real_starting_before',
  real_finishing_after:  '%s_real_finishing_after',
  real_finishing_before: '%s_real_finishing_before',

  containing_date:       '%s_containing_date',
  not_containing_date:   '%s_not_containing_date',
  overlapping_date:      '%s_overlapping_date',
  not_overlapping_date:  '%s_not_overlapping_date',
  real_containing_date:  '%s_real_containing_date',
  real_overlapping_date: '%s_real_overlapping_date',

  current?:              'current_%s?,
  current_on?:           'current_%s_on?,
  start:                 '%s_start',
  finish:                '%s_finish',
  real:                  'real_%s',
  real_start:            '%s_real_start',
  real_finish:           '%s_real_finish',              }

period.direct_method_names If the period is marked as direct access, without the field name, then these method names will replace the default ones.
Default value:

{ current_on:          'happening_in',
  containing:          'during',
  not_containing:      'not_during',
  real_containing:     'real_during',

  containing_date:     'during_date',
  not_containing_date: 'not_during_date',

  current_on?:         'happening_in?',
  start:               'start_at',
  finish:              'finish_at',
  real:                'real_time',
  real_start:          'real_start_at',
  real_finish:         'real_finish_at',   }

Interval configurations

These are the keys available to configure Interval features:

interval.enabled Enables interval handler by this gem, not Rails's implementation.
Default value: true

Arel configurations

These are the keys available to configure Arel features:

arel.expose_function_helper_on When provided, the initializer will expose the Arel function helper (FN) on the given module. Recommended 'PG::Fn'.
Default value: nil

arel.infix_operators List of Arel INFIX operators that will be made available for using as methods on Arel::Nodes::Node and Arel::Attribute. The pairs are method_name and operator.
Default value:

{ 'contained_by'        => '<@',
  'has_key'             => '?',
  'has_all_keys'        => '?&',
  'has_any_keys'        => '?|',
  'strictly_left'       => '<<',
  'strictly_right'      => '>>',
  'doesnt_right_extend' => '&<',
  'doesnt_left_extend'  => '&>',
  'adjacent_to'         => '-|-' }

Full-text search configurations

These are the keys available to configure Full-Text Search features:

full_text_search.enabled Enables full text search handler by this gem.
Default value: true

full_text_search.base_method The name of the method to be used on any ActiveRecord::Base to initialize model-based full text search features.
Default value: :torque_search_for

full_text_search.default_language Defines the default language when generating search vector columns.
Default value: 'english'

full_text_search.default_mode Defines the default mode to be used when generating full text search queries. It can be one of the following: :default for TO_TSQUERY, :phrase for PHRASETO_TSQUERY, :plain for PLAINTO_TSQUERY, or :web for WEBSEARCH_TO_TSQUERY.
Default value: :phrase

full_text_search.default_index_type Defines the default index type to be used when creating a search vector. It still requires that the column requests an index.
Default value: true

Predicate builder configurations

These are the keys available to configure Predicate Builder features:

predicate_builder.enabled List of handlers that are enabled by default. Possible values are: regexp, arel_attribute, enumerator_lazy.
Default value: %i[regexp arel_attribute enumerator_lazy]

predicate_builder.handle_array_attributes When active, values provided to array attributes will be handled more friendly. It will use the +ANY+ operator on an equality check and overlaps when the given value is an array.
Default value: false

predicate_builder.lazy_timeout Make sure that the predicate builder will not spend more than 20ms trying to produce the underlying array.
Default value: 0.02

predicate_builder.lazy_limit Since lazy array is uncommon, it is better to limit the number of entries we try to pull so we don't cause a timeout or a long wait iteration.
Default value: 2_000

Clone this wiki locally