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

Parameters:



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

Parameters:

  • method (Symbol)
  • *args (Array)

Returns:

  • (self)

    return self for all command methods

  • (Object)

    return response from all query methods



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)

Parameters:

  • other (Relation)

    the other relation to find the difference with

Returns:

  • (Gateway)

    return a gateway if the adapters are equal

  • (Algebra::Difference)

    return a normal dfference when the adapters are not equal



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

Returns:

  • (self)


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)

Parameters:

  • other (Relation)

    the other relation to find the intersect with

Returns:

  • (Gateway)

    return a gateway if the adapters are equal

  • (Algebra::Intersection)

    return a normal intersection when the adapters are not equal



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) }

Parameters:

  • other (Relation)

    the other relation to join

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

Returns:

  • (Gateway)

    return a gateway if the adapters are equal

  • (Algebra::Join)

    return a normal join when the adapters are not equal

  • (Algebra::Restriction)

    return a normal restriction when the adapters are not equal for a theta-join



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)

Parameters:

  • other (Relation)

    the other relation to find the product with

Returns:

  • (Gateway)

    return a gateway if the adapters are equal

  • (Algebra::Product)

    return a normal product when the adapters are not equal



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

Parameters:

  • method (Symbol)

Returns:

  • (Boolean)


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

Parameters:

  • summarize_with (Gateway, Relation, Header, #to_ary) (defaults to: TABLE_DEE)

Yields:

  • (function)

    Evaluate a summarization function

Yield Parameters:

  • context (Evaluator::Context)

    the context to evaluate the function within

Returns:

  • (Gateway)

    return a gateway if the adapters are equal, or there is no adapter

  • (Algebra::Summarization)

    return a normal summarization when the adapters are not equal



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)

Parameters:

  • other (Relation)

    the other relation to find the union with

Returns:

  • (Gateway)

    return a gateway if the adapters are equal

  • (Algebra::Union)

    return a normal union when the adapters are not equal



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

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