Class: XCAPClient::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/xcapclient/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auid, data = {}) ⇒ Application

:nodoc:

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/xcapclient/application.rb', line 7

def initialize(auid, data={})  #:nodoc:
	
	@auid = auid
	
	# Check application data.
	raise ConfigError, "Application `data' must be a hash ('#{@auid}')" unless (Hash === data)
	
	@xmlns = data[:xmlns].freeze
	@mime_type = data[:mime_type].freeze
	@document_name = data[:document_name] || "index"
	@scope = data[:scope] || :user
	@scope.freeze
	
	# Check auid.
	raise ConfigError, "Application `auid' must be a non empty string ('#{@auid}')" unless String === @auid && ! @auid.empty?
		
	# Check xmlns.
	raise ConfigError, "Application `xmlns' must be a non empty string ('#{@auid}')" unless String === @xmlns && ! @xmlns.empty?
	
	# Check mime-type.
	raise ConfigError, "Application `mime_type' must be a non empty string ('#{@auid}')" unless String === @mime_type && ! @mime_type.empty?
	
	# Check document_name
	raise ConfigError, "Application `document_name' must be a non empty string ('#{@auid}')" unless String === @document_name && ! @document_name.empty?
	
	# Check scope.
	raise ConfigError, "Application `scope' must be :user or :global ('#{@auid}')" unless [:user, :global].include?(@scope)
	
	# Create first document.
	@documents = {}
	@documents[@document_name] = Document.new(@document_name)
	
end

Instance Attribute Details

#auidObject (readonly)

Returns the value of attribute auid.



5
6
7
# File 'lib/xcapclient/application.rb', line 5

def auid
  @auid
end

#document_nameObject (readonly)

Returns the value of attribute document_name.



5
6
7
# File 'lib/xcapclient/application.rb', line 5

def document_name
  @document_name
end

#mime_typeObject (readonly)

Returns the value of attribute mime_type.



5
6
7
# File 'lib/xcapclient/application.rb', line 5

def mime_type
  @mime_type
end

#scopeObject (readonly)

Returns the value of attribute scope.



5
6
7
# File 'lib/xcapclient/application.rb', line 5

def scope
  @scope
end

#xmlnsObject (readonly)

Returns the value of attribute xmlns.



5
6
7
# File 'lib/xcapclient/application.rb', line 5

def xmlns
  @xmlns
end

Instance Method Details

#add_document(document_name) ⇒ Object

Creates a new XCAPClient::Document for this application with name document_name.

Raises:



53
54
55
56
57
58
# File 'lib/xcapclient/application.rb', line 53

def add_document(document_name)
	raise DocumentError, "document '#{document_name}' already exists" if @documents[document_name]
	@documents[document_name] = Document.new(document_name)
	
	return @documents[document_name]
end

#document(document_name = nil) ⇒ Object

Get the XCAPClient::Document with name document_name within this application. If the parameter is not set, the default document is got.



43
44
45
# File 'lib/xcapclient/application.rb', line 43

def document(document_name=nil)
	@documents[document_name || @document_name]
end

#documentsObject

Get an Array containing all the documents created for this application.



48
49
50
# File 'lib/xcapclient/application.rb', line 48

def documents
	@documents
end