Sha256: 8e4e9dc4d8307e5534df96bf3f2c542d1654bec482cc3885fadd22969d6e8898

Contents?: true

Size: 1.24 KB

Versions: 35

Compression:

Stored size: 1.24 KB

Contents

module ROM
  class Relation
    # Interface for objects that can be materialized into a loaded relation
    #
    # @api public
    module Materializable
      # @abstract
      #
      # @api public
      def call(*)
        raise NotImplementedError, "#{self.class}#call must be implemented"
      end

      # 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(&block)
        return to_enum unless block
        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

35 entries across 35 versions & 2 rubygems

Version Path
rom-3.3.3 lib/rom/relation/materializable.rb
rom-3.3.2 lib/rom/relation/materializable.rb
rom-3.3.1 lib/rom/relation/materializable.rb
rom-core-4.0.0.beta2 lib/rom/relation/materializable.rb
rom-3.3.0 lib/rom/relation/materializable.rb
rom-core-4.0.0.beta1 lib/rom/relation/materializable.rb
rom-3.2.3 lib/rom/relation/materializable.rb
rom-3.2.2 lib/rom/relation/materializable.rb
rom-3.2.1 lib/rom/relation/materializable.rb
rom-3.2.0 lib/rom/relation/materializable.rb
rom-3.1.0 lib/rom/relation/materializable.rb
rom-3.0.3 lib/rom/relation/materializable.rb
rom-3.0.2 lib/rom/relation/materializable.rb
rom-3.0.1 lib/rom/relation/materializable.rb
rom-3.0.0 lib/rom/relation/materializable.rb
rom-3.0.0.rc2 lib/rom/relation/materializable.rb
rom-3.0.0.rc1 lib/rom/relation/materializable.rb
rom-3.0.0.beta3 lib/rom/relation/materializable.rb
rom-3.0.0.beta2 lib/rom/relation/materializable.rb
rom-3.0.0.beta1 lib/rom/relation/materializable.rb