Sha256: eb175a23aa725ce148fa5ae179cfb360b58f5bfc7582b73ccb7807fae04a98ad

Contents?: true

Size: 1.58 KB

Versions: 2

Compression:

Stored size: 1.58 KB

Contents

require 'rom/ra'

module ROM

  # Base relation class
  #
  # Relation is a proxy for the dataset object provided by the adapter, it
  # forwards every method to the dataset that's why "native" interface of the
  # underlying adapter is available in the relation. This interface, however, is
  # considered to private and should not be used outside of the relation instance.
  #
  # ROM builds sub-classes of this class for every relation defined in the env
  # for easy inspection and extensibility - every adapter can provide extensions
  # for those sub-classes but there is always a vanilla relation instance stored
  # in the schema registry.
  #
  # Relation instances also have access to the experimental ROM::RA interface
  # giving in-memory relational operations that are very handy, especially when
  # dealing with joined relations or data coming from different sources.
  #
  # @api public
  class Relation
    include Charlatan.new(:dataset)
    include Equalizer.new(:header, :dataset)
    include RA

    attr_reader :header

    # @api private
    def self.finalize(env, relation)
      # noop
    end

    # @api private
    def initialize(dataset, header = dataset.header)
      super
      @header = header.dup.freeze
    end

    # @api private
    def each(&block)
      return to_enum unless block
      dataset.each(&block)
    end

    # @api private
    def insert(tuple)
      dataset.insert(tuple)
      self
    end

    # @api private
    def update(tuple)
      dataset.update(tuple)
      self
    end

    # @api private
    def delete
      dataset.delete
      self
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rom-0.3.1 lib/rom/relation.rb
rom-0.3.0 lib/rom/relation.rb