Module: Rein::Util
- Defined in:
- lib/rein/util.rb
Overview
The Util module provides utility methods for handling options.
Class Method Summary collapse
-
.add_not_valid_suffix_if_required(sql, options) ⇒ Object
Returns a new string with the suffix appended if required.
- .conditions_with_if(conditions, options = {}) ⇒ Object
- .constraint_name(table, attribute, suffix, options = {}) ⇒ Object
- .wrap_identifier(attribute) ⇒ Object
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, ) suffix = [: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, = {}) if [:if].present? "NOT (#{[: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, = {}) [: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 |