Sha256: ab68d3a854f8d151020a3689a6d5e47014a8899692354e90912c7dce47f842da

Contents?: true

Size: 1.62 KB

Versions: 30

Compression:

Stored size: 1.62 KB

Contents

require 'singleton'

class OEHClient::Config::SpaceManager
	include Singleton


	attr_accessor :spaces

	# Constructor.  Initialize the spaces collection as a new hash
	def initialize
		@spaces 	= Hash.new
	end

	# register_space is a wrapper method that converts the passed Hash object to an instance of the 
	#  OEHClient::Config::Space object, which is passed to the register method
	def register_space(space_config={})

		# Pass a new instance of the space object to the register_space method
		register(OEHClient::Config::Space.create(space_config))

	end

	# get_space returns the instance of the OEHClient::Config::Space
	def get(site_key)

		# raise the OEHClient::Exception::InvalidSpaceException if the space has not been registered
		raise OEHClient::Exception::InvalidSpaceException unless (@spaces.has_key?(site_key))

		# return the space configuration instance
		@spaces[site_key]

	end

	private

	# register adds the instance of the OEHClient::Config::Space object to the spaces hash, using the 
	#  site_key value as the hash KEY
	def register(space_instance)

		# Raise OEHClient::Exception::InvalidSpaceException if the space instance is NOT valie
		raise OEHClient::Exception::InvalidSpaceConfigException unless (space_instance.is_valid?)
		# Raise the OEHClient::Exception::InvalidSpaceObjectException if the space_instance object is not
		#  the proper type of object (OEHClient::Config::Space)
		raise OEHClient::Exception::InvalidSpaceObjectException unless (space_instance.kind_of?(OEHClient::Config::Space))

		# Assign the space instance to the spaces collection
		@spaces[space_instance.site_key] = space_instance 

	end





end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
oeh-client-2.2.9 lib/oehclient/config/space_manager.rb
oeh-client-2.2.8 lib/oehclient/config/space_manager.rb
oeh-client-2.2.7 lib/oehclient/config/space_manager.rb
oeh-client-2.2.6 lib/oehclient/config/space_manager.rb
oeh-client-2.2.5 lib/oehclient/config/space_manager.rb
oeh-client-2.2.4 lib/oehclient/config/space_manager.rb
oeh-client-2.2.3 lib/oehclient/config/space_manager.rb
oeh-client-2.2.1 lib/oehclient/config/space_manager.rb
oeh-client-2.2.0 lib/oehclient/config/space_manager.rb
oeh-client-2.1.0 lib/oehclient/config/space_manager.rb
oeh-client-2.0.3 lib/oehclient/config/space_manager.rb
oeh-client-2.0.2 lib/oehclient/config/space_manager.rb
oeh-client-2.0.1 lib/oehclient/config/space_manager.rb
oeh-client-1.1.0 lib/oehclient/config/space_manager.rb
oeh-client-0.3.4 lib/oehclient/config/space_manager.rb
oeh-client-0.3.3 lib/oehclient/config/space_manager.rb
oeh-client-0.3.2 lib/oehclient/config/space_manager.rb
oeh-client-0.3.1 lib/oehclient/config/space_manager.rb
oeh-client-0.3.0 lib/oehclient/config/space_manager.rb
oeh-client-0.2.5 lib/oehclient/config/space_manager.rb