module SQL::Maker::Util
Public Class Methods
bind_param(sql, bind)
click to toggle source
# File lib/sql/maker/util.rb, line 48 def bind_param(sql, bind) raise SQL::Maker::Error.new('bind arity mismatch') if sql.count('?') != bind.size i = -1; sql.gsub('?') { SQL::Maker::Quoting.quote(bind[i+=1]) } end
included(klass)
click to toggle source
# File lib/sql/maker/util.rb, line 5 def self.included(klass) klass.extend(self) end
quote_identifier(label, quote_char, name_sep)
click to toggle source
# File lib/sql/maker/util.rb, line 40 def quote_identifier(label, quote_char, name_sep) return label if label == '*'; return label unless name_sep; label.to_s.split(/#{Regexp.escape(name_sep)}/).map {|e| e == '*' ? e : "#{quote_char}#{e}#{quote_char}" }.join(name_sep) end
Public Instance Methods
array_wrap(val)
click to toggle source
# File lib/sql/maker/util.rb, line 13 def array_wrap(val) val.is_a?(Array) ? val : [val] end
bind_param(sql, bind)
click to toggle source
# File lib/sql/maker/util.rb, line 48 def bind_param(sql, bind) raise SQL::Maker::Error.new('bind arity mismatch') if sql.count('?') != bind.size i = -1; sql.gsub('?') { SQL::Maker::Quoting.quote(bind[i+=1]) } end
croak(message)
click to toggle source
# File lib/sql/maker/util.rb, line 9 def croak(message) raise SQL::Maker::Error.new(message) end
parse_args(*args)
click to toggle source
perl-like argument parser of my ($a, $b) = @_;
# File lib/sql/maker/util.rb, line 18 def parse_args(*args) if args.size > 1 # method('a', 'b') #=> ['a', 'b'] return args else args = args.first case args when Hash # method('a' => 'b') #=> ['a', 'b'] # method('a' => ['b', 'c']) #=> ['a', ['b', 'c']] # method('a' => {'b' => 'c'}) #=> ['a', {'b' => 'c'}] args.each.first when Array # method(['a', 'b']) #=> ['a', 'b'] return args else # method('a') #=> ['a', nil] return [args, nil] end end end
quote_identifier(label, quote_char, name_sep)
click to toggle source
# File lib/sql/maker/util.rb, line 40 def quote_identifier(label, quote_char, name_sep) return label if label == '*'; return label unless name_sep; label.to_s.split(/#{Regexp.escape(name_sep)}/).map {|e| e == '*' ? e : "#{quote_char}#{e}#{quote_char}" }.join(name_sep) end