module ROM
  class Session

    # @api public
    class Environment < ROM::Environment
      include Proxy

      attr_reader :environment
      private :environment

      attr_reader :tracker
      private :tracker

      attr_reader :memory
      private :memory

      def initialize(environment, tracker)
        @environment = environment
        @tracker     = tracker
        initialize_memory
      end

      # @api public
      def [](name)
        memory[name]
      end

      # @api private
      def commit
        tracker.commit
      end

      private

      # @api private
      def initialize_memory
        @memory = Hash.new { |memory, name| memory[name] = build_relation(name) }
      end

      # @api private
      def build_relation(name)
        Session::Relation.build(environment[name], tracker, tracker.identity_map(name))
      end

    end # Registry

  end # Session
end # ROM

module ROM
  class Session

    # Session-specific environment wrapping ROM's environment
    #
    # It works exactly the same as ROM::Environment except it returns
    # session relations
    #
    # @api public
    class Environment < ROM::Environment
      include Proxy

      attr_reader :environment, :tracker, :memory
      private :environment, :tracker, :memory

      # @api private
      def initialize(environment, tracker)
        @environment = environment
        @tracker     = tracker
        initialize_memory
      end

      # Return a relation identified by name
      #
      # @param [Symbol] name of a relation
      #
      # @return [Session::Relation] rom's relation wrapped by session
      #
      # @api public
      def [](name)
        memory[name]
      end

      # @api private
      def commit
        tracker.commit
      end

      private

      # @api private
      def initialize_memory
        @memory = Hash.new { |memory, name| memory[name] = build_relation(name) }
      end

      # @api private
      def build_relation(name)
        Session::Relation.build(environment[name], tracker, tracker.identity_map(name))
      end

    end # Environment

  end # Session
end # ROM

Simplify Session::Environment a little and add docs
Simplify Session::Environment a little and add docs
