Class: ROM::Relation::Curried
- Inherits:
-
Object
- Object
- ROM::Relation::Curried
- Extended by:
- Initializer
- Includes:
- Pipeline, Materializable
- Defined in:
- core/lib/rom/relation/curried.rb
Overview
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
Instance Attribute Summary collapse
-
#arity ⇒ Integer
readonly
View's arity.
-
#curry_args ⇒ Array
readonly
Arguments that will be passed to curried view.
-
#relation ⇒ Relation
readonly
The source relation that is curried.
-
#view ⇒ Symbol
readonly
The name of relation's view method.
Instance Method Summary collapse
-
#>>(other) ⇒ Relation::Composite
included
from Pipeline::Operator
Compose two relation with a left-to-right composition.
-
#call(*args) ⇒ Loaded, Curried
(also: #[])
Load relation if args match the arity.
-
#curried? ⇒ true
private
Return if this lazy relation is curried.
-
#each {|Hash, Object| ... } ⇒ Object
included
from Materializable
Yield relation tuples.
-
#first ⇒ Object
included
from Materializable
Return first tuple from a relation coerced to an array.
-
#map_with(*names) ⇒ Relation::Composite
included
from Pipeline
Send data through specified mappers.
-
#one ⇒ Object
included
from Materializable
Delegate to loaded relation and return one object.
-
#one! ⇒ Object
included
from Materializable
Delegate to loaded relation and return one object.
- #respond_to_missing?(name, include_private = false) ⇒ Boolean private
-
#to_a ⇒ Object
(also: #to_ary)
Relations are coercible to an array but a curried relation cannot be coerced When something tries to do this, an exception will be raised.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'core/lib/rom/relation/curried.rb', line 108 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 |
Instance Attribute Details
#arity ⇒ Integer (readonly)
Returns View's arity.
38 |
# File 'core/lib/rom/relation/curried.rb', line 38 option :arity, type: Types::Strict::Integer |
#curry_args ⇒ Array (readonly)
Returns Arguments that will be passed to curried view.
42 |
# File 'core/lib/rom/relation/curried.rb', line 42 option :curry_args, default: -> { EMPTY_ARRAY } |
#relation ⇒ Relation (readonly)
Returns The source relation that is curried.
30 |
# File 'core/lib/rom/relation/curried.rb', line 30 param :relation |
#view ⇒ Symbol (readonly)
Returns The name of relation's view method.
34 |
# File 'core/lib/rom/relation/curried.rb', line 34 option :view, type: Types::Strict::Symbol |
Instance Method Details
#>>(other) ⇒ Relation::Composite Originally defined in module Pipeline::Operator
Compose two relation with a left-to-right composition
#call(*args) ⇒ Loaded, Curried Also known as: []
Load relation if args match the arity
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'core/lib/rom/relation/curried.rb', line 49 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 |
#curried? ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return if this lazy relation is curried
86 87 88 |
# File 'core/lib/rom/relation/curried.rb', line 86 def curried? true end |
#each {|Hash, Object| ... } ⇒ Object Originally defined in module Materializable
Yield relation tuples
#first ⇒ Object Originally defined in module Materializable
Return first tuple from a relation coerced to an array
#map_with(*names) ⇒ Relation::Composite Originally defined in module Pipeline
Send data through specified mappers
#one ⇒ Object Originally defined in module Materializable
Delegate to loaded relation and return one object
#one! ⇒ Object Originally defined in module Materializable
Delegate to loaded relation and return one object
#respond_to_missing?(name, include_private = false) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
91 92 93 |
# File 'core/lib/rom/relation/curried.rb', line 91 def respond_to_missing?(name, include_private = false) super || relation.respond_to?(name, include_private) end |
#to_a ⇒ Object Also known as: to_ary
Relations are coercible to an array but a curried relation cannot be coerced When something tries to do this, an exception will be raised
72 73 74 75 76 77 78 |
# File 'core/lib/rom/relation/curried.rb', line 72 def to_a raise( ArgumentError, "#{relation.class}##{view} arity is #{arity} " \ "(#{curry_args.size} args given)" ) end |