File: virtual_row_method_block.rb

package info (click to toggle)
ruby-sequel 5.63.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,408 kB
  • sloc: ruby: 113,747; makefile: 3
file content (44 lines) | stat: -rw-r--r-- 1,247 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen-string-literal: true
#
# These modifies virtual row blocks so that you can pass a block
# when calling a method to change the behavior.  It only exists
# for backwards compatibility with previous Sequel versions, and
# is not recommended for new applications.
# 
# To load the extension:
#
#   Sequel.extension :virtual_row_method_block

#
module Sequel
  module SQL
    class VirtualRow < BasicObject
      include(Module.new do
        # Handle blocks passed to methods and change the behavior.
        def method_missing(m, *args, &block)
          if block
            if args.empty?
              Function.new(m)
            else
              case args.shift
              when :*
                Function.new(m, *args).*
              when :distinct
                Function.new(m, *args).distinct
              when :over
                opts = args.shift || OPTS
                f = Function.new(m, *::Kernel.Array(opts[:args]))
                f = f.* if opts[:*]
                f.over(opts)
              else
                Kernel.raise(Error, 'unsupported VirtualRow method argument used with block')
              end
            end
          else
            super
          end
        end
      end)
    end
  end
end