Sha256: 805ad4fc657b98e501aec09f10c9acbb4e9115ab63767fdea9f622bc8f934396

Contents?: true

Size: 1.06 KB

Versions: 10

Compression:

Stored size: 1.06 KB

Contents

# rubocop:disable Naming/MethodName
# rubocop:disable Naming/UncommunicativeMethodParamName

module Arel
  module Nodes
    # https://www.postgresql.org/docs/10/functions-string.html
    class Substring < Arel::Nodes::Node
      attr_reader :string
      attr_reader :pattern
      attr_reader :escape

      def initialize(string, pattern, escape)
        @string = string
        @pattern = pattern
        @escape = escape
      end
    end
  end

  module Visitors
    class ToSql
      def visit_Arel_Nodes_Substring(o, collector)
        collector << 'substring('
        visit o.string, collector
        collector << ' from '
        visit o.pattern, collector
        unless o.escape.nil?
          collector << ' for '
          visit o.escape, collector
        end
        collector << ')'
      end
    end

    class Dot
      def visit_Arel_Nodes_Substring(o)
        visit_edge o, 'string'
        visit_edge o, 'pattern'
        visit_edge o, 'escape'
      end
    end
  end
end

# rubocop:enable Naming/MethodName
# rubocop:enable Naming/UncommunicativeMethodParamName

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
arel_toolkit-0.4.9 lib/arel/extensions/substring.rb
arel_toolkit-0.4.8 lib/arel/extensions/substring.rb
arel_toolkit-0.4.7 lib/arel/extensions/substring.rb
arel_toolkit-0.4.6 lib/arel/extensions/substring.rb
arel_toolkit-0.4.5 lib/arel/extensions/substring.rb
arel_toolkit-0.4.4 lib/arel/extensions/substring.rb
arel_toolkit-0.4.3 lib/arel/extensions/substring.rb
arel_toolkit-0.4.2 lib/arel/extensions/substring.rb
arel_toolkit-0.4.1 lib/arel/extensions/substring.rb
arel_toolkit-0.4.0 lib/arel/extensions/substring.rb