Sha256: 0b22556c638bf57154e53bf2a77b993db239ffa9a8b462215cfda9eb38363fff

Contents?: true

Size: 1.12 KB

Versions: 9

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module ROM
  class Relation
    # Interface for objects that can be materialized into a loaded relation
    #
    # @api public
    module Materializable
      # Coerce the relation to an array
      #
      # @return [Array]
      #
      # @api public
      def to_a
        call.to_a
      end
      alias_method :to_ary, :to_a

      # Yield relation tuples
      #
      # @yield [Hash,Object]
      #
      # @api public
      def each
        return to_enum unless block_given?

        to_a.each { |tuple| yield(tuple) }
      end

      # Delegate to loaded relation and return one object
      #
      # @return [Object]
      #
      # @see Loaded#one
      #
      # @api public
      def one
        call.one
      end

      # Delegate to loaded relation and return one object
      #
      # @return [Object]
      #
      # @see Loaded#one
      #
      # @api public
      def one!
        call.one!
      end

      # Return first tuple from a relation coerced to an array
      #
      # @return [Object]
      #
      # @api public
      def first
        to_a.first
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rom-core-5.3.2 lib/rom/relation/materializable.rb
rom-core-5.3.1 lib/rom/relation/materializable.rb
rom-core-5.3.0 lib/rom/relation/materializable.rb
rom-core-5.2.6 lib/rom/relation/materializable.rb
rom-core-5.2.5 lib/rom/relation/materializable.rb
rom-core-5.2.4 lib/rom/relation/materializable.rb
rom-core-5.2.3 lib/rom/relation/materializable.rb
rom-core-5.2.2 lib/rom/relation/materializable.rb
rom-core-5.2.1 lib/rom/relation/materializable.rb