class ROM::Relation::Curried

Curried relation is a special relation proxy used by auto-curry mechanism.

When a relation view method is called without all arguments, a curried proxy is returned that can be fully applied later on.

Curried relations are typically used for relation composition

@api public

Public Instance Methods

[](*args)
Alias for: call
call(*args) click to toggle source

Load relation if args match the arity

@return [Loaded,Curried]

@api public

# File lib/rom/relation/curried.rb, line 51
def call(*args)
  all_args = curry_args + args

  if all_args.empty?
    raise ArgumentError, "curried #{relation.class}##{view} relation was called without any arguments"
  end

  if args.empty?
    self
  elsif arity == all_args.size
    Loaded.new(relation.__send__(view, *all_args))
  else
    __new__(relation, curry_args: all_args)
  end
end
Also aliased as: []
curried?() click to toggle source

Return if this lazy relation is curried

@return [true]

@api private

# File lib/rom/relation/curried.rb, line 88
def curried?
  true
end
respond_to_missing?(name, include_private = false) click to toggle source

@api private

Calls superclass method
# File lib/rom/relation/curried.rb, line 93
def respond_to_missing?(name, include_private = false)
  super || relation.respond_to?(name, include_private)
end
to_a() click to toggle source

Relations are coercible to an array but a curried relation cannot be coerced When something tries to do this, an exception will be raised

@raise ArgumentError

@api public

# File lib/rom/relation/curried.rb, line 74
def to_a
  raise(
    ArgumentError,
    "#{relation.class}##{view} arity is #{arity} " \
    "(#{curry_args.size} args given)"
  )
end
Also aliased as: to_ary
to_ary()
Alias for: to_a

Private Instance Methods

__new__(relation, **new_opts) click to toggle source

@api private

# File lib/rom/relation/curried.rb, line 100
def __new__(relation, **new_opts)
  self.class.new(relation, **options, **new_opts)
end
composite_class() click to toggle source

@api private

# File lib/rom/relation/curried.rb, line 105
def composite_class
  Relation::Composite
end
method_missing(meth, *args, &block) click to toggle source

@api private

Calls superclass method
# File lib/rom/relation/curried.rb, line 110
def method_missing(meth, *args, &block)
  if relation.respond_to?(meth)
    response = relation.__send__(meth, *args, &block)

    super if response.is_a?(self.class)

    if response.is_a?(Relation) || response.is_a?(Graph) || response.is_a?(Wrap) || response.is_a?(Composite)
      __new__(response)
    else
      response
    end
  else
    super
  end
end