Class Array
In: lib/sequel_core/core_ext.rb
lib/sequel_core/core_sql.rb
Parent: Object

Methods

Public Instance methods

True if the array is not empty and all of its elements are arrays of size 2. This is used to determine if the array could be a specifier of conditions, used similarly to a hash but allowing for duplicate keys.

   hash.to_a.all_two_pairs? # => true unless hash is empty

[Source]

    # File lib/sequel_core/core_ext.rb, line 14
14:   def all_two_pairs?
15:     !empty? && all?{|i| (Array === i) && (i.length == 2)}
16:   end

Return a Sequel::SQL::CaseExpression with this array as the conditions and the given default value.

[Source]

    # File lib/sequel_core/core_sql.rb, line 10
10:   def case(default, expression = nil)
11:     ::Sequel::SQL::CaseExpression.new(self, default, expression)
12:   end

Removes and returns the last member of the array if it is a hash. Otherwise, an empty hash is returned This method is useful when writing methods that take an options hash as the last parameter. For example:

  def validate_each(*args, &block)
    opts = args.extract_options!
    ...
  end

[Source]

    # File lib/sequel_core/core_ext.rb, line 26
26:   def extract_options!
27:     last.is_a?(Hash) ? pop : {}
28:   end

Return a Sequel::SQL::Array created from this array. Used if this array contains all two pairs and you want it treated as an SQL array instead of a ordered hash-like conditions.

[Source]

    # File lib/sequel_core/core_sql.rb, line 17
17:   def sql_array
18:     ::Sequel::SQL::SQLArray.new(self)
19:   end

Return a Sequel::SQL::BooleanExpression created from this array, matching all of the conditions.

[Source]

    # File lib/sequel_core/core_sql.rb, line 23
23:   def sql_expr
24:     sql_expr_if_all_two_pairs
25:   end

Return a Sequel::SQL::BooleanExpression created from this array, matching none of the conditions.

[Source]

    # File lib/sequel_core/core_sql.rb, line 29
29:   def sql_negate
30:     sql_expr_if_all_two_pairs(:AND, true)
31:   end

Return a Sequel::SQL::BooleanExpression created from this array, matching any of the conditions.

[Source]

    # File lib/sequel_core/core_sql.rb, line 35
35:   def sql_or
36:     sql_expr_if_all_two_pairs(:OR)
37:   end

Return a Sequel::SQL::BooleanExpression representing an SQL string made up of the concatenation of this array‘s elements. If an argument is passed it is used in between each element of the array in the SQL concatenation.

[Source]

    # File lib/sequel_core/core_sql.rb, line 43
43:   def sql_string_join(joiner=nil)
44:     if joiner
45:       args = self.inject([]) do |m, a|
46:         m << a
47:         m << joiner
48:       end
49:       args.pop
50:     else
51:       args = self
52:     end
53:     args = args.collect{|a| a.is_one_of?(Symbol, ::Sequel::SQL::Expression, ::Sequel::LiteralString, TrueClass, FalseClass, NilClass) ? a : a.to_s}
54:     ::Sequel::SQL::StringExpression.new('||''||', *args)
55:   end

Concatenates an array of strings into an SQL string. ANSI SQL and C-style comments are removed, as well as excessive white-space.

[Source]

    # File lib/sequel_core/core_sql.rb, line 59
59:   def to_sql
60:     map {|l| ((m = /^(.*)--/.match(l)) ? m[1] : l).chomp}.join(' '). \
61:       gsub(/\/\*.*\*\//, '').gsub(/\s+/, ' ').strip
62:   end

Return a Sequel::SQL::BooleanExpression created from this array, not matching any of the conditions.

[Source]

   # File lib/sequel_core/core_sql.rb, line 4
4:   def ~
5:     sql_expr_if_all_two_pairs(:OR, true)
6:   end

[Validate]