Module: Rein::Util

Defined in:
lib/rein/util.rb

Overview

The Util module provides utility methods for handling options.

Class Method Summary collapse

Class Method Details

.conditions_with_if(conditions, options = {}) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/rein/util.rb', line 4

def self.conditions_with_if(conditions, options = {})
  if options[:if].present?
    "NOT (#{options[:if]}) OR (#{conditions})"
  else
    conditions
  end
end

.constraint_name(table, attribute, suffix, options = {}) ⇒ Object



12
13
14
# File 'lib/rein/util.rb', line 12

def self.constraint_name(table, attribute, suffix, options = {})
  options[:name].presence || "#{table}_#{attribute}_#{suffix}"
end

.wrap_identifier(attribute) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/rein/util.rb', line 16

def self.wrap_identifier(attribute)
  if /^".*"$/.match?(attribute)
    attribute
  else
    "\"#{attribute}\""
  end
end