Sha256: 4abb255f32c04e12e07cad03a8b3fe273007a7b0ae273c3b65a2abffd5b1320d

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require 'rom/relation/lazy'

module ROM
  class Relation
    class Curried < Lazy
      option :name, type: Symbol, reader: true
      option :arity, type: Integer, reader: true, default: -1
      option :curry_args, type: Array, reader: true, default: EMPTY_ARRAY

      # Load relation if args match the arity
      #
      # @return [Loaded,Lazy,Curried]
      # @see Lazy#call
      #
      # @api public
      def call(*args)
        if arity != -1
          all_args = curry_args + args

          if arity == all_args.size
            Loaded.new(relation.__send__(name, *all_args))
          else
            __new__(relation, curry_args: all_args)
          end
        else
          super
        end
      end
      alias_method :[], :call

      # Return if this lazy relation is curried
      #
      # @return [true]
      #
      # @api private
      def curried?
        true
      end

      private

      # @api private
      def __new__(relation, new_opts = {})
        Curried.new(relation, options.merge(new_opts))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-0.6.0.beta1 lib/rom/relation/curried.rb