Sha256: ef23b8e2365365ebd8b387662cb58e3eaee0b1a204a7c52f5c2680d520d2a6d3

Contents?: true

Size: 980 Bytes

Versions: 12

Compression:

Stored size: 980 Bytes

Contents

require 'rom/schema/attribute'

module ROM
  module SQL
    # @api private
    class Function < ROM::Schema::Attribute
      def sql_literal(ds)
        if name
          func.as(name).sql_literal(ds)
        else
          func.sql_literal(ds)
        end
      end

      def name
        meta[:alias] || super
      end

      def qualified
        meta(
          func: ::Sequel::SQL::Function.new(func.name, *func.args.map { |arg| arg.respond_to?(:qualified) ? arg.qualified : arg })
        )
      end

      def is(other)
        ::Sequel::SQL::BooleanExpression.new(:'=', func, other)
      end

      private

      def func
        meta[:func]
      end

      def method_missing(meth, *args)
        if func
          if func.respond_to?(meth)
            meta(func: func.__send__(meth, *args))
          else
            super
          end
        else
          meta(func: Sequel::SQL::Function.new(meth.to_s.upcase, *args))
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rom-sql-1.3.1 lib/rom/sql/function.rb
rom-sql-1.3.0 lib/rom/sql/function.rb
rom-sql-1.2.2 lib/rom/sql/function.rb
rom-sql-1.2.1 lib/rom/sql/function.rb
rom-sql-1.2.0 lib/rom/sql/function.rb
rom-sql-1.1.2 lib/rom/sql/function.rb
rom-sql-1.1.1 lib/rom/sql/function.rb
rom-sql-1.1.0 lib/rom/sql/function.rb
rom-sql-1.0.3 lib/rom/sql/function.rb
rom-sql-1.0.2 lib/rom/sql/function.rb
rom-sql-1.0.1 lib/rom/sql/function.rb
rom-sql-1.0.0 lib/rom/sql/function.rb