module Utils
Constants
- INVALID_NAME_CHAR
- RAISERROR_STATE_BASE
Primes in the interval [100, 255]. This enumerator can be queried by classes that generate RAISERROR statements to provide unique-ish context by passing the next multiple of one of the values taken from this enumerator for each RAISERROR statement output (as a literal number in the generated SQL). This will assist
Private Class Methods
chars_to_tab(prev, tab_width: 4)
click to toggle source
# File lib/mkxms/mssql/utils.rb, line 155 def chars_to_tab(prev, tab_width: 4) (prev.chars.length + 3) % 4 + 1 end
code_sym_for(s)
click to toggle source
# File lib/mkxms/mssql/utils.rb, line 142 def code_sym_for(s) s.gsub(self::INVALID_NAME_CHAR, '_').downcase.to_sym end
dry_run?()
click to toggle source
# File lib/mkxms/mssql/utils.rb, line 170 def dry_run? @dry_run.tap do |v| (break @dry_run = !!(ENV.fetch('DRY_RUN', '') =~ /^(y(es)?|t(rue)?|1)$/i)) if v.nil? end end
expand_tabs(s, tab_width: 4)
click to toggle source
# File lib/mkxms/mssql/utils.rb, line 159 def expand_tabs(s, tab_width: 4) return s unless s.include? "\t" s.each_line.map do |l| while l.include? "\t" l.sub!("\t") {|m| ' ' * chars_to_tab($`, tab_width: tab_width)} end l end.join('') end
newline_prefixed(s)
click to toggle source
# File lib/mkxms/mssql/utils.rb, line 151 def newline_prefixed(s) "\n" + s end
unquoted_name(s)
click to toggle source
# File lib/mkxms/mssql/utils.rb, line 146 def unquoted_name(s) return s unless s[0] == '[' && s[-1] == ']' return s[1...-1].gsub(']]', ']') end