Module: Squeel::Configuration

Included in:
Squeel
Defined in:
lib/squeel/configuration.rb

Overview

The Squeel configuration module. The Squeel module extends this to provide its configuration capability.

Instance Method Summary collapse

Instance Method Details

#alias_predicate(new_name, existing_name) ⇒ Object

Create an alias to an existing predication method. The _any/_all variations will be created automatically.

Parameters:

  • new_name (Symbol)

    The alias name

  • existing_name (Symbol)

    The existing predicate name

Raises:

  • (ArgumentError)

    The existing name is an _any/_all variation, and not the original predicate name



47
48
49
50
51
52
# File 'lib/squeel/configuration.rb', line 47

def alias_predicate(new_name, existing_name)
  raise ArgumentError, 'the existing name should be the base name, not an _any/_all variation' if existing_name.to_s =~ /(_any|_all)$/
  ['', '_any', '_all'].each do |suffix|
    Nodes::PredicateMethods.class_eval "alias :#{new_name}#{suffix} :#{existing_name}#{suffix} unless defined?(#{new_name}#{suffix})"
  end
end

#configure {|config| ... } ⇒ Object

Start a Squeel configuration block in an initializer.

Examples:

Load hash and symbol extensions

Squeel.configure do |config|
  config.load_core_extensions :hash, :symbol
end

Alias a predicate

Squeel.configure do |config|
  config.alias_ptedicate :is_less_than, :lt
end

Yields:

  • (config)

    A configuration block



22
23
24
# File 'lib/squeel/configuration.rb', line 22

def configure
  yield self
end

#load_core_extensions(sym) ⇒ Object #load_core_extensions(sym1, sym2) ⇒ Object

Load core extensions for Hash, Symbol, or both

Overloads:

  • #load_core_extensions(sym) ⇒ Object

    Load a single extension

    Parameters:

    • sym (Symbol)

      :hash or :symbol

  • #load_core_extensions(sym1, sym2) ⇒ Object

    Load both extensions

    Parameters:

    • sym1 (Symbol)

      :hash or :symbol

    • sym2 (Symbol)

      :hash or :symbol



35
36
37
38
39
40
# File 'lib/squeel/configuration.rb', line 35

def load_core_extensions(*exts)
  deprecate 'Core extensions are deprecated and will be removed in Squeel 2.0.'
  exts.each do |ext|
    require "squeel/core_ext/#{ext}"
  end
end