Sha256: 4ff1e6f0db6335ec6564c7ccde88eeaef7655676712f28c8a555bcddbb0586fd

Contents?: true

Size: 814 Bytes

Versions: 4

Compression:

Stored size: 814 Bytes

Contents

module FcrepoWrapper
  # Configuraton that comes from static and dynamic sources.
  class Settings < Delegator
    def __getobj__
      @static_config # return object we are delegating to, required
    end

    alias static_config __getobj__

    def __setobj__(obj)
      @static_config = obj
    end

    def initialize(static_config)
      super
      @static_config = static_config
    end

    ##
    # Get the port this fcrepo instance is running at
    def port
      @port ||= static_config.port
      @port ||= random_open_port.to_s
    end

    private

      def random_open_port
        socket = Socket.new(:INET, :STREAM, 0)
        begin
          socket.bind(Addrinfo.tcp('127.0.0.1', 0))
          socket.local_address.ip_port
        ensure
          socket.close
        end
      end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fcrepo_wrapper-0.3.3 lib/fcrepo_wrapper/settings.rb
fcrepo_wrapper-0.3.2 lib/fcrepo_wrapper/settings.rb
fcrepo_wrapper-0.3.1 lib/fcrepo_wrapper/settings.rb
fcrepo_wrapper-0.3.0 lib/fcrepo_wrapper/settings.rb