Class: ActiveCMIS::Server
- Inherits:
-
Object
- Object
- ActiveCMIS::Server
- Includes:
- Internal::Caching
- Defined in:
- lib/active_cmis/server.rb
Overview
This class is used to manage different CMIS servers.
Instance Attribute Summary collapse
-
#endpoint ⇒ URI
readonly
The location of the server.
-
#logger ⇒ Logger
readonly
A default logger for derived repositories.
Class Method Summary collapse
-
.endpoints ⇒ {(URI, Logger) => Server}
The cache of known Servers.
-
.new(endpoint, logger = nil, authentication_info = nil) ⇒ Server
Cached by endpoint and logger.
Instance Method Summary collapse
-
#authenticate(*authentication_info) ⇒ void
This returns a new Server object using the specified authentication info.
-
#clear_repositories ⇒ void
Reset cache of Repository objects.
-
#initialize(endpoint, logger, authentication_info = nil) ⇒ Server
constructor
A connection needs the URL to a CMIS REST endpoint.
- #inspect ⇒ String
-
#repositories ⇒ <{:id, :name} => String>
Lists all the available repositories.
-
#repository(repository_id, authentication_info = self.authentcation_info) ⇒ Repository
Returns the _Repository identified by the ID Authentication will take place with the optional second paramater, if it is absent and there is server authentcation then the server authentication will be used.
- #to_s ⇒ String
Methods included from Internal::Caching
Constructor Details
#initialize(endpoint, logger, authentication_info = nil) ⇒ Server
A connection needs the URL to a CMIS REST endpoint.
It’s used to manage all communication with the CMIS Server
40 41 42 43 44 45 46 47 48 |
# File 'lib/active_cmis/server.rb', line 40 def initialize(endpoint, logger, authentication_info = nil) @endpoint = endpoint @logger = logger method, *params = authentication_info if method conn.authenticate(method, *params) end end |
Instance Attribute Details
#endpoint ⇒ URI (readonly)
Returns The location of the server.
6 7 8 |
# File 'lib/active_cmis/server.rb', line 6 def endpoint @endpoint end |
#logger ⇒ Logger (readonly)
Returns A default logger for derived repositories.
8 9 10 |
# File 'lib/active_cmis/server.rb', line 8 def logger @logger end |
Class Method Details
.endpoints ⇒ {(URI, Logger) => Server}
Returns The cache of known Servers.
21 22 23 |
# File 'lib/active_cmis/server.rb', line 21 def self.endpoints @endpoints ||= Hash.new {|h, k| h[k] = Hash.new {|h2, k2| h2[k2] = {}}} end |
.new(endpoint, logger = nil, authentication_info = nil) ⇒ Server
Returns Cached by endpoint and logger.
11 12 13 14 15 16 17 18 |
# File 'lib/active_cmis/server.rb', line 11 def self.new(endpoint, logger = nil, authentication_info = nil) endpoint = case endpoint when URI; endpoint else URI(endpoint.to_s) end server = super(endpoint, logger || ActiveCMIS.default_logger, authentication_info) endpoints[endpoint.to_s][authentication_info][logger] ||= server end |
Instance Method Details
#authenticate(*authentication_info) ⇒ void
This method returns an undefined value.
This returns a new Server object using the specified authentication info
55 56 57 |
# File 'lib/active_cmis/server.rb', line 55 def authenticate(*authentication_info) self.class.new(endpoint, logger, authentication_info) end |
#clear_repositories ⇒ void
This method returns an undefined value.
Reset cache of Repository objects
85 86 87 |
# File 'lib/active_cmis/server.rb', line 85 def clear_repositories @cached_repositories = {} end |
#inspect ⇒ String
26 27 28 |
# File 'lib/active_cmis/server.rb', line 26 def inspect "Server #{@endpoint}" end |
#repositories ⇒ <{:id, :name} => String>
Lists all the available repositories
93 94 95 96 97 |
# File 'lib/active_cmis/server.rb', line 93 def repositories repositories = repository_info.xpath("/app:service/app:workspace/cra:repositoryInfo", NS::COMBINED) repositories.map {|ri| next {:id => ri.xpath("ns:repositoryId", "ns" => NS::CMIS_CORE).text, :name => ri.xpath("ns:repositoryName", "ns" => NS::CMIS_CORE).text }} end |
#repository(repository_id, authentication_info = self.authentcation_info) ⇒ Repository
Returns the _Repository identified by the ID Authentication will take place with the optional second paramater, if it is absent and there is server authentcation then the server authentication will be used
Cached by the repository_id and, authentcation info. The cache can be reset by calling clear_repositories.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/active_cmis/server.rb', line 70 def repository(repository_id, authentication_info = self.authentcation_info) cached_repositories[[repository_id, authentication_info]] ||= begin repository_data = repository_info. xpath("/app:service/app:workspace[cra:repositoryInfo/c:repositoryId[child::text() = '#{repository_id}']]", NS::COMBINED) if repository_data.empty? raise Error::ObjectNotFound.new("The repository #{repository_id} doesn't exist") else Repository.new(self, conn.dup, logger.dup, repository_data, authentication_info) end end end |
#to_s ⇒ String
30 31 32 |
# File 'lib/active_cmis/server.rb', line 30 def to_s "Server " + @endpoint.to_s + " : " + repositories.map {|h| h[:name] + "(#{h[:id]})"}.join(", ") end |