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.
-
#options ⇒ Hash
readonly
Options to be used by the HTTP objects.
Class Method Summary collapse
-
.endpoints ⇒ {(URI, Logger) => Server}
The cache of known Servers.
-
.new(endpoint, logger = nil, authentication_info = nil, options = 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, options = 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 = @authentication_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, options = nil) ⇒ Server
A connection needs the URL to a CMIS REST endpoint.
It’s used to manage all communication with the CMIS Server
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/active_cmis/server.rb', line 42 def initialize(endpoint, logger, authentication_info = nil, = nil) @endpoint = endpoint @logger = logger @options = || {} method, *params = authentication_info @authentication_info = 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 |
#options ⇒ Hash (readonly)
Returns Options to be used by the HTTP objects.
10 11 12 |
# File 'lib/active_cmis/server.rb', line 10 def @options end |
Class Method Details
.endpoints ⇒ {(URI, Logger) => Server}
Returns The cache of known Servers.
23 24 25 |
# File 'lib/active_cmis/server.rb', line 23 def self.endpoints @endpoints ||= Hash.new {|h, k| h[k] = Hash.new {|h2, k2| h2[k2] = {}}} end |
.new(endpoint, logger = nil, authentication_info = nil, options = nil) ⇒ Server
Returns Cached by endpoint and logger.
13 14 15 16 17 18 19 20 |
# File 'lib/active_cmis/server.rb', line 13 def self.new(endpoint, logger = nil, authentication_info = nil, = 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
59 60 61 |
# File 'lib/active_cmis/server.rb', line 59 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
93 94 95 |
# File 'lib/active_cmis/server.rb', line 93 def clear_repositories @cached_repositories = {} end |
#inspect ⇒ String
28 29 30 |
# File 'lib/active_cmis/server.rb', line 28 def inspect "Server #{@endpoint}" end |
#repositories ⇒ <{:id, :name} => String>
Lists all the available repositories
101 102 103 104 105 |
# File 'lib/active_cmis/server.rb', line 101 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 = @authentication_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.
74 75 76 77 |
# File 'lib/active_cmis/server.rb', line 74 def repository(repository_id, authentication_info = @authentication_info) key = [repository_id, authentication_info] cached_repositories[key] ||= uncached_repository(*key) end |
#to_s ⇒ String
32 33 34 |
# File 'lib/active_cmis/server.rb', line 32 def to_s "Server " + @endpoint.to_s + " : " + repositories.map {|h| h[:name] + "(#{h[:id]})"}.join(", ") end |