Sha256: ddfc3909fa6f0b12129bbf49413f6ba9a7bba42762746a8068988c0a459ad82d

Contents?: true

Size: 1.76 KB

Versions: 7

Compression:

Stored size: 1.76 KB

Contents

module Torque
  module PostgreSQL
    include ActiveSupport::Configurable

    # Allow nested configurations
    config.define_singleton_method(:nested) do |name, &block|
      klass = Class.new(ActiveSupport::Configurable::Configuration).new
      block.call(klass) if block
      send("#{name}=", klass)
    end

    # Configure ENUM features
    config.nested(:enum) do |enum|

      # Indicates if the enum features on ActiveRecord::Base should be initiated
      # automatically or not
      enum.initializer = false

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

      # Indicates if bang methods like 'disabled!' should update the record on
      # database or not
      enum.save_on_bang = true

      # Specify the namespace of each enum type of value
      enum.namespace = ::Object.const_set('Enum', Module.new)

      # Specify the scopes for I18n translations
      enum.i18n_scopes = [
        'activerecord.attributes.%{model}.%{attr}.%{value}',
        'activerecord.attributes.%{attr}.%{value}',
        'activerecord.enums.%{type}.%{value}',
        'enum.%{type}.%{value}',
        'enum.%{value}'
      ]

      # Specify the scopes for I18n translations but with type only
      enum.i18n_type_scopes = Enumerator.new do |yielder|
        enum.i18n_scopes.each do |key|
          next if key.include?('%{model}') || key.include?('%{attr}')
          yielder << key
        end
      end

    end

    # Configure auxiliary statement features
    config.nested(:auxiliary_statement) do |cte|

      # Define the key that is used on auxiliary statements to send extra
      # arguments to format string or send on a proc
      cte.send_arguments_key = :uses

    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
torque-postgresql-0.1.7 lib/torque/postgresql/config.rb
torque-postgresql-0.1.6 lib/torque/postgresql/config.rb
torque-postgresql-0.1.5 lib/torque/postgresql/config.rb
torque-postgresql-0.1.4 lib/torque/postgresql/config.rb
torque-postgresql-0.1.3 lib/torque/postgresql/config.rb
torque-postgresql-0.1.2 lib/torque/postgresql/config.rb
torque-postgresql-0.1.1 lib/torque/postgresql/config.rb