Class: Veritas::Relation::Gateway

Inherits:
Veritas::Relation show all
Defined in:
lib/veritas/relation/gateway.rb

Overview

A relation backed by an adapter

Constant Summary collapse

DECORATED_CLASS =
superclass

Instance Method Summary collapse

Constructor Details

#initialize(adapter, relation) ⇒ undefined

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.

Initialize a Gateway



40
41
42
43
# File 'lib/veritas/relation/gateway.rb', line 40

def initialize(adapter, relation)
  @adapter  = adapter
  @relation = relation
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ self, 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.

Proxy the message to the relation



243
244
245
# File 'lib/veritas/relation/gateway.rb', line 243

def method_missing(method, *args, &block)
  forwardable?(method) ? forward(method, *args, &block) : super
end

Instance Method Details

#difference(other) ⇒ Gateway, Algebra::Difference

Return the diferrence between relations

Examples:

difference = gateway.difference(other)


170
171
172
# File 'lib/veritas/relation/gateway.rb', line 170

def difference(other)
  binary_operation(__method__, other, Algebra::Difference)
end

#each {|tuple| ... } ⇒ self

Iterate over each row in the results

Examples:

gateway = Gateway.new(adapter, relation)
gateway.each { |tuple| ... }

Yields:

  • (tuple)

Yield Parameters:

  • tuple (Tuple)

    each tuple in the results



59
60
61
62
63
# File 'lib/veritas/relation/gateway.rb', line 59

def each
  return to_enum unless block_given?
  tuples.each { |tuple| yield tuple }
  self
end

#intersect(other) ⇒ Gateway, Algebra::Intersection

Return the intersection between relations

Examples:

intersect = gateway.intersect(other)


152
153
154
# File 'lib/veritas/relation/gateway.rb', line 152

def intersect(other)
  binary_operation(__method__, other, Algebra::Intersection)
end

#join(other) {|relation| ... } ⇒ Gateway, ...

Return a relation that is the join of two relations

Examples:

natural join

join = relation.join(other)

theta-join using a block

join = relation.join(other) { |r| r.a.gte(r.b) }

Yields:

  • (relation)

    optional block to restrict the tuples with

Yield Parameters:

  • relation (Relation)

    the context to evaluate the restriction with

Yield Returns:

  • (Function, #call)

    predicate to restrict the tuples with



94
95
96
97
98
99
100
# File 'lib/veritas/relation/gateway.rb', line 94

def join(other)
  if block_given?
    super
  else
    binary_operation(__method__, other, Algebra::Join)
  end
end

#product(other) ⇒ Gateway, Algebra::Product

Return a relation that is the cartesian product of two relations

Examples:

product = gateway.product(other)


116
117
118
# File 'lib/veritas/relation/gateway.rb', line 116

def product(other)
  binary_operation(__method__, other, Algebra::Product)
end

#respond_to?(method) ⇒ 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.

Test if the method is supported on this object



225
226
227
# File 'lib/veritas/relation/gateway.rb', line 225

def respond_to?(method, *)
  super || forwardable?(method)
end

#summarize(summarize_with = TABLE_DEE) {|function| ... } ⇒ Gateway, Algebra::Summarization

Return a summarized relation

Examples:

with no arguments

summarization = gateway.summarize do |context|
  context.add(:count, context[:id].count)
end

with a relation

summarization = gateway.summarize(relation) do |context|
  context.add(:count, context[:id].count)
end

with a header

summarization = gateway.summarize([ :name ]) do |context|
  context.add(:count, context[:id].count)
end

with another gateway

summarization = gateway.summarize(other_gateway) do |context|
  context.add(:count, context[:id].count)
end

Yields:

  • (function)

    Evaluate a summarization function

Yield Parameters:

  • context (Evaluator::Context)

    the context to evaluate the function within



210
211
212
213
214
215
216
# File 'lib/veritas/relation/gateway.rb', line 210

def summarize(summarize_with = TABLE_DEE, &block)
  if summarize_merge?(summarize_with)
    summarize_merge(summarize_with, &block)
  else
    summarize_split(summarize_with, &block)
  end
end

#union(other) ⇒ Gateway, Algebra::Union

Return the union between relations

Examples:

union = gateway.union(other)


134
135
136
# File 'lib/veritas/relation/gateway.rb', line 134

def union(other)
  binary_operation(__method__, other, Algebra::Union)
end