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

.add_not_valid_suffix_if_required(sql, options) ⇒ Object

Returns a new string with the suffix appended if required



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

def self.add_not_valid_suffix_if_required(sql, options)
  suffix = options[:validate] == false ? ' NOT VALID' : ''
  "#{sql}#{suffix}"
end

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



10
11
12
13
14
15
16
# File 'lib/rein/util.rb', line 10

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



18
19
20
# File 'lib/rein/util.rb', line 18

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

.wrap_identifier(attribute) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/rein/util.rb', line 22

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