Sha256: dd92372ad3df5a813432b203b55bd21bd28917bc64ff56e5258eb1885e11e33b

Contents?: true

Size: 1021 Bytes

Versions: 10

Compression:

Stored size: 1021 Bytes

Contents

require 'rom/sql/dsl'
require 'rom/sql/function'

module ROM
  module SQL
    # @api private
    class ProjectionDSL < DSL
      # @api public
      def `(value)
        expr = ::Sequel::VIRTUAL_ROW.instance_eval { `#{value}` }
        ::ROM::SQL::Attribute.new(type(:string)).meta(sql_expr: expr)
      end

      # @api private
      def respond_to_missing?(name, include_private = false)
        super || type(name)
      end

      private

      # @api private
      def type(identifier)
        type_name = ::Dry::Core::Inflector.classify(identifier)
        types.const_get(type_name) if types.const_defined?(type_name)
      end

      # @api private
      def types
        ::ROM::SQL::Types
      end

      # @api private
      def method_missing(meth, *args, &block)
        if schema.key?(meth)
          schema[meth]
        else
          type = type(meth)

          if type
            ::ROM::SQL::Function.new(type)
          else
            super
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

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