yaccl 0.1.5 → 1.0.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/lib/yaccl/children.rb +55 -0
  3. data/lib/yaccl/connection.rb +147 -0
  4. data/lib/yaccl/document.rb +62 -0
  5. data/lib/yaccl/folder.rb +76 -0
  6. data/lib/yaccl/helpers.rb +59 -0
  7. data/lib/yaccl/item.rb +11 -0
  8. data/lib/yaccl/object.rb +122 -0
  9. data/lib/yaccl/object_factory.rb +27 -0
  10. data/lib/yaccl/policy.rb +26 -0
  11. data/lib/yaccl/property_definition.rb +32 -0
  12. data/lib/yaccl/query.rb +53 -0
  13. data/lib/yaccl/query_result.rb +15 -0
  14. data/lib/yaccl/relationship.rb +18 -0
  15. data/lib/yaccl/repository.rb +108 -0
  16. data/lib/yaccl/server.rb +37 -0
  17. data/lib/yaccl/type.rb +106 -0
  18. data/lib/yaccl/version.rb +1 -1
  19. data/lib/yaccl.rb +21 -11
  20. data/readme.md +0 -3
  21. data/spec/{model/document_spec.rb → document_spec.rb} +4 -4
  22. data/spec/{model/folder_spec.rb → folder_spec.rb} +6 -6
  23. data/spec/helper.rb +12 -12
  24. data/spec/{model/object_spec.rb → object_spec.rb} +6 -6
  25. data/spec/relationship_spec.rb +19 -0
  26. data/spec/repository_spec.rb +150 -0
  27. data/spec/server_spec.rb +22 -0
  28. data/spec/{model/type_spec.rb → type_spec.rb} +6 -4
  29. data/yaccl.gemspec +1 -0
  30. metadata +48 -50
  31. data/examples/create_type_manual.rb +0 -40
  32. data/lib/yaccl/model/document.rb +0 -68
  33. data/lib/yaccl/model/folder.rb +0 -74
  34. data/lib/yaccl/model/item.rb +0 -9
  35. data/lib/yaccl/model/object.rb +0 -159
  36. data/lib/yaccl/model/object_factory.rb +0 -24
  37. data/lib/yaccl/model/policy.rb +0 -20
  38. data/lib/yaccl/model/property_definition.rb +0 -66
  39. data/lib/yaccl/model/relationship.rb +0 -22
  40. data/lib/yaccl/model/repository.rb +0 -155
  41. data/lib/yaccl/model/server.rb +0 -13
  42. data/lib/yaccl/model/type.rb +0 -146
  43. data/lib/yaccl/model.rb +0 -11
  44. data/lib/yaccl/services/acl_services.rb +0 -23
  45. data/lib/yaccl/services/discovery_services.rb +0 -29
  46. data/lib/yaccl/services/internal/browser_binding_service.rb +0 -170
  47. data/lib/yaccl/services/internal/simple_cache.rb +0 -103
  48. data/lib/yaccl/services/multi_filing_services.rb +0 -22
  49. data/lib/yaccl/services/navigation_services.rb +0 -84
  50. data/lib/yaccl/services/object_services.rb +0 -211
  51. data/lib/yaccl/services/policy_services.rb +0 -30
  52. data/lib/yaccl/services/relationship_services.rb +0 -18
  53. data/lib/yaccl/services/repository_services.rb +0 -67
  54. data/lib/yaccl/services/versioning_services.rb +0 -69
  55. data/lib/yaccl/services.rb +0 -34
  56. data/spec/model/relationship_spec.rb +0 -15
  57. data/spec/model/repository_spec.rb +0 -138
  58. data/spec/model/server_spec.rb +0 -16
  59. data/spec/services/navigation_services_spec.rb +0 -64
  60. data/spec/services/object_services_spec.rb +0 -44
  61. data/spec/services/repository_services_spec.rb +0 -35
@@ -1,155 +0,0 @@
1
- module YACCL
2
- module Model
3
- class Repository
4
- attr_reader :id
5
- attr_reader :name
6
- attr_reader :description
7
- attr_reader :root_folder_id
8
- attr_reader :capabilities
9
- attr_reader :url
10
- attr_reader :latest_change_log_token
11
- attr_reader :vendor_name
12
- attr_reader :cmis_version_supported
13
- attr_reader :acl_capabilities
14
- attr_reader :product_name
15
- attr_reader :product_version
16
- attr_reader :thin_client_uri
17
- attr_reader :changes_on_type
18
- attr_reader :root_folder_url
19
-
20
- def ==(other)
21
- return true if other.equal?(self)
22
- return false unless other.kind_of?(self.class)
23
- id == other.id
24
- end
25
-
26
- def to_s
27
- name
28
- end
29
-
30
- def self.create(raw_repository)
31
- Repository.new(raw_repository)
32
- end
33
-
34
- def initialize(raw)
35
- @id = raw[:repositoryId]
36
- @name = raw[:repositoryName]
37
- @description = raw[:repositoryDescription]
38
- @root_folder_id = raw[:rootFolderId]
39
- @capabilities = raw[:capabilities]
40
- @url = raw[:repositoryUrl]
41
- @latest_change_log_token = raw[:latestChangeLogToken]
42
- @vendor_name = raw[:vendorName]
43
- @cmis_version_supported = raw[:cmisVersionSupported]
44
- @acl_capabilities = raw[:aclCapabilities]
45
- @product_name = raw[:productName]
46
- @product_version = raw[:productVersion]
47
- @thin_client_uri = raw[:thinClientUri]
48
- @changes_on_type = raw[:changesOnType]
49
- @root_folder_url = raw[:rootFolderUrl]
50
- end
51
-
52
- def new_folder
53
- Folder.new(id)
54
- end
55
-
56
- def new_document
57
- Document.new(id)
58
- end
59
-
60
- def new_relationship
61
- Relationship.new(id)
62
- end
63
-
64
- def new_policy
65
- Policy.new(id)
66
- end
67
-
68
- def new_item
69
- Item.new(id)
70
- end
71
-
72
- # object
73
-
74
- def root
75
- ObjectFactory.create(id, Services.get_object(id, root_folder_id, nil, false, nil, nil, false, false))
76
- end
77
-
78
- def object(cmis_object_id)
79
- ObjectFactory.create(id, Services.get_object(id, cmis_object_id, nil, false, nil, nil, false, false))
80
- end
81
-
82
- # type
83
-
84
- def type(type_id)
85
- Type.create(id, Services.get_type_definition(id, type_id))
86
- end
87
-
88
- def types
89
- _types(Services.get_type_descendants(id, nil, nil, true))
90
- end
91
-
92
- def create_type(type)
93
- Type.create(id, Services.create_type(id, type.to_hash))
94
- end
95
-
96
- # relationship
97
-
98
- def create(object)
99
- properties = object.create_properties
100
- if object.is_a? Folder
101
- raise 'create object in folder'
102
- elsif object.is_a? Document
103
- raise 'create document in folder'
104
- elsif object.is_a? Relationship
105
- o = Services.create_relationship(id, properties, nil, nil, nil)
106
- elsif object.is_a? Policy
107
- raise 'create policy in folder'
108
- elsif object.is_a? Item
109
- raise 'create item in folder'
110
- else
111
- raise "Unexpected base_type_id: #{object.base_type_id}"
112
- end
113
- ObjectFactory.create(id, o)
114
- end
115
-
116
- # discovery
117
-
118
- def query(statement, max_items=nil, skip_count=nil, &block)
119
- result = Services.query(id, statement, nil, nil, nil, nil, max_items, skip_count)
120
- result[:results].map! { |o| ObjectFactory.create(id, o) }
121
- result[:num_items] = result.delete(:numItems)
122
- result[:has_more_items] = result.delete(:hasMoreItems)
123
-
124
- yield(result) if block_given?
125
- result[:results]
126
- end
127
-
128
- def query_for_each_chunk(statement, chunk_size, &block)
129
- skip_count = 0
130
- has_more_items = true
131
- while has_more_items
132
- result = Services.query(id, statement, nil, nil, nil, nil, chunk_size, skip_count)
133
- yield(result[:results].map! { |o| ObjectFactory.create(id, o) }) unless result[:results].empty?
134
- has_more_items = result[:hasMoreItems]
135
- skip_count += result[:results].size
136
- end
137
- end
138
-
139
- def content_changes(change_log_token)
140
- Services.get_content_changes(id, change_log_token, nil, nil, nil, nil)
141
- end
142
-
143
- private
144
-
145
- def _types(arr)
146
- types = []
147
- arr.each do |t|
148
- types << Type.create(id, t[:type])
149
- types << _types(t[:children]) if t.has_key?(:children)
150
- end
151
- types.flatten
152
- end
153
- end
154
- end
155
- end
@@ -1,13 +0,0 @@
1
- module YACCL
2
- module Model
3
- class Server
4
- def self.repositories
5
- Services.get_repositories.values.map { |r| Repository.create(r) }
6
- end
7
-
8
- def self.repository(repository_id)
9
- Repository.create(Services.get_repository_info(repository_id).values.first)
10
- end
11
- end
12
- end
13
- end
@@ -1,146 +0,0 @@
1
- module YACCL
2
- module Model
3
- class Type
4
- attr_accessor :repository_id
5
- attr_accessor :id
6
- attr_accessor :local_name
7
- attr_accessor :local_namespace
8
- attr_accessor :query_name
9
- attr_accessor :display_name
10
- attr_accessor :base_id
11
- attr_accessor :parent_id
12
- attr_accessor :description
13
- attr_accessor :creatable
14
- attr_accessor :fileable
15
- attr_accessor :queryable
16
- attr_accessor :controllable_policy
17
- attr_accessor :controllable_acl
18
- attr_accessor :fulltext_indexed
19
- attr_accessor :included_in_supertype_query
20
- attr_accessor :property_definitions
21
- # document type
22
- attr_accessor :versionable
23
- attr_accessor :content_stream_allowed
24
- # relationship type
25
- attr_accessor :allowed_source_types
26
- attr_accessor :allowed_target_types
27
-
28
- def self.create(repository_id, raw)
29
- type = Type.new(raw)
30
- type.repository_id = repository_id
31
- type
32
- end
33
-
34
- def initialize(hash={})
35
- @id = hash[:id]
36
- @local_name = hash[:localName]
37
- @local_namespace = hash[:localNamespace]
38
- @query_name = hash[:queryName]
39
- @display_name = hash[:displayName]
40
- @base_id = hash[:baseId]
41
- @parent_id = hash[:parentId]
42
- @description = hash[:description]
43
- @creatable = hash[:creatable]
44
- @fileable = hash[:fileable]
45
- @queryable = hash[:queryable]
46
- @controllable_policy = hash[:controllablePolicy]
47
- @controllable_acl = hash[:controllableACL]
48
- @fulltext_indexed = hash[:fulltextIndexed]
49
- @included_in_supertype_query = hash[:includedInSupertypeQuery]
50
- @property_definitions = hash[:propertyDefinitions] || {}
51
- @property_definitions.each { |k, v| @property_definitions[k] = PropertyDefinition.new(v) }
52
- # document type
53
- @versionable = hash[:versionable]
54
- @content_stream_allowed = hash[:contentStreamAllowed]
55
- # relationship type
56
- @allowed_source_types = hash[:allowedSourceTypes]
57
- @allowed_target_types = hash[:allowedTargetTypes]
58
- end
59
-
60
- def add_property_definition(property)
61
- @property_definitions[property[:id]] = property
62
- end
63
-
64
- def update(changed_property_defs)
65
- hash = to_hash
66
- new_defs = changed_property_defs.map(&:to_hash).inject({}) do |result, element|
67
- result[element[:id]] = element
68
- result
69
- end
70
- hash[:propertyDefinitions] = new_defs
71
-
72
- Type.create(repository_id, Services.update_type(repository_id, hash))
73
- end
74
-
75
- def delete
76
- Services.delete_type(repository_id, id)
77
- end
78
-
79
- def new_object
80
- object = case base_id
81
- when 'cmis:document'
82
- Document.new(repository_id)
83
- when 'cmis:folder'
84
- Folder.new(repository_id)
85
- when 'cmis:relationship'
86
- Relationship.new(repository_id)
87
- when 'cmis:policy'
88
- Policy.new(repository_id)
89
- when 'cmis:item'
90
- Item.new(repository_id)
91
- else
92
- raise "Unsupported base type: #{base_id}"
93
- end
94
- object.object_type_id = id
95
- object
96
- end
97
-
98
- def document_type?
99
- base_id == 'cmis:document'
100
- end
101
-
102
- def folder_type?
103
- base_id == 'cmis:folder'
104
- end
105
-
106
- def relationship_type?
107
- base_id == 'cmis:relationship'
108
- end
109
-
110
- def policy_type?
111
- base_id == 'cmis:policy'
112
- end
113
-
114
- def item_type?
115
- base_id == 'cmis:item'
116
- end
117
-
118
- def to_hash
119
- hash = {}
120
- hash[:id] = id
121
- hash[:localName] = local_name
122
- hash[:localNamespace] = local_namespace
123
- hash[:queryName]= query_name
124
- hash[:displayName]= display_name
125
- hash[:baseId]= base_id
126
- hash[:parentId]= parent_id
127
- hash[:description]= description
128
- hash[:creatable]= creatable
129
- hash[:fileable]= fileable
130
- hash[:queryable]= queryable
131
- hash[:controllablePolicy]= controllable_policy
132
- hash[:controllableACL]= controllable_acl
133
- hash[:fulltextIndexed]= fulltext_indexed
134
- hash[:includedInSupertypeQuery]= included_in_supertype_query
135
- hash[:propertyDefinitions]= property_definitions.to_hash
136
- # document type
137
- hash[:versionable] = versionable unless versionable.nil?
138
- hash[:contentStreamAllowed] = content_stream_allowed unless content_stream_allowed.nil?
139
- # relationship type
140
- hash[:allowedSourceTypes] = allowed_source_types unless allowed_source_types.nil?
141
- hash[:allowedTargetTypes] = allowed_target_types unless allowed_target_types.nil?
142
- hash
143
- end
144
- end
145
- end
146
- end
data/lib/yaccl/model.rb DELETED
@@ -1,11 +0,0 @@
1
- require 'yaccl/model/object'
2
- require 'yaccl/model/object_factory'
3
- require 'yaccl/model/document'
4
- require 'yaccl/model/folder'
5
- require 'yaccl/model/item'
6
- require 'yaccl/model/policy'
7
- require 'yaccl/model/relationship'
8
- require 'yaccl/model/repository'
9
- require 'yaccl/model/type'
10
- require 'yaccl/model/property_definition'
11
- require 'yaccl/model/server'
@@ -1,23 +0,0 @@
1
- module YACCL
2
- module ACLServices
3
- def get_acl(repository_id, cmis_object_id, only_basic_permissions, succinct=false)
4
- required = {succinct: succinct,
5
- cmisselector: 'acl',
6
- repositoryId: repository_id,
7
- objectId: cmis_object_id}
8
- optional = {onlyBasicPermissions: only_basic_permissions}
9
- perform_request(required, optional)
10
- end
11
-
12
- def apply_acl(repository_id, cmis_object_id, add_aces, remove_aces, acl_propagation, succinct=false)
13
- required = {succinct: succinct,
14
- cmisaction: 'applyACL',
15
- repositoryId: repository_id,
16
- objectId: cmis_object_id}
17
- optional = {addACEs: add_aces,
18
- removeACEs: remove_aces,
19
- ACLPropagation: acl_propagation}
20
- perform_request(required, optional)
21
- end
22
- end
23
- end
@@ -1,29 +0,0 @@
1
- module YACCL
2
- module DiscoveryServices
3
- def query(repository_id, statement, search_all_versions, include_relationships, rendition_filter, include_allowable_actions, max_items, skip_count, succinct=false)
4
- required = {succinct: succinct,
5
- cmisselector: 'query',
6
- repositoryId: repository_id,
7
- q: statement}
8
- optional = {searchAllVersions: search_all_versions,
9
- includeRelationships: include_relationships,
10
- renditionFilter: rendition_filter,
11
- includeAllowableActions: include_allowable_actions,
12
- maxItems: max_items,
13
- skipCount: skip_count}
14
- perform_request(required, optional)
15
- end
16
-
17
- def get_content_changes(repository_id, change_log_token, include_properties, include_policy_ids, include_acl, max_items, succinct=false)
18
- required = {succinct: succinct,
19
- cmisselector: 'contentChanges',
20
- repositoryId: repository_id}
21
- optional = {changeLogToken: change_log_token,
22
- includeProperties: include_properties,
23
- includePolicyIds: include_policy_ids,
24
- includeAcl: include_acl,
25
- maxItems: max_items}
26
- perform_request(required, optional)
27
- end
28
- end
29
- end
@@ -1,170 +0,0 @@
1
- require 'date'
2
- require 'typhoeus'
3
- require 'net/http/post/multipart'
4
- require 'multi_json'
5
- require_relative 'simple_cache'
6
-
7
- module YACCL
8
- module Services
9
- class CMISRequestError < RuntimeError; end
10
-
11
- module Internal
12
- class BrowserBindingService
13
-
14
- @@url_cache = SimpleCache::MemoryCache.new
15
-
16
- def initialize(service_url, basic_auth_username=nil, basic_auth_password=nil, succinct_properties=true)
17
- @service_url = service_url
18
- @basement = Basement.new(basic_auth_username, basic_auth_password)
19
- @succinct_properties = succinct_properties
20
- end
21
-
22
- def perform_request(required_params={}, optional_params={})
23
- headers = required_params[:properties].delete(:headers) if required_params[:properties]
24
- headers ||= {}
25
- url = get_url(required_params.delete(:repositoryId), required_params[:objectId])
26
-
27
- required_params[:succinct] ||= @succinct_properties
28
- optional_params.reject! { |_, v| v.nil? }
29
-
30
- params = transform_hash(required_params.merge(optional_params))
31
-
32
- check(params)
33
-
34
- response = if params.has_key?(:cmisaction)
35
- if params.has_key?(:content)
36
- @basement.multipart_post(url, params, headers)
37
- else
38
- @basement.post(url: url, body: params, headers: headers)
39
- end
40
- else
41
- @basement.get(url: url, query: params, headers: headers)
42
- end
43
-
44
-
45
- result = response.body
46
-
47
- content_type = if response.respond_to?(:content_type)
48
- response.content_type
49
- else
50
- response.headers['Content-Type']
51
- end
52
-
53
- result = MultiJson.load(result, symbolize_keys: true) if content_type =~ /application\/json/
54
-
55
- unless (200...300).include?(response.code.to_i)
56
- if result.is_a?(Hash) && result.has_key?(:exception)
57
- raise CMISRequestError, "#{response.code} -- #{result[:exception]} -- #{result[:message]}"
58
- else
59
- raise CMISRequestError, "#{response.code} -- #{result}"
60
- end
61
- end
62
-
63
- result
64
- end
65
-
66
- private
67
-
68
- def get_url(repository_id, cmis_object_id)
69
- if repository_id.nil?
70
- @service_url
71
- else
72
- repository_urls(repository_id)[cmis_object_id ? :root_folder_url : :repository_url]
73
- end
74
- end
75
-
76
- def repository_urls(repository_id)
77
- if @@url_cache[repository_id].nil?
78
- repository_infos = MultiJson.load(@basement.get(url: @service_url).body , symbolize_keys: false)
79
- raise "No repository found with ID #{repository_id}." unless repository_infos.has_key?(repository_id)
80
- repository_info = repository_infos[repository_id]
81
- @@url_cache[repository_id] = { repository_url: repository_info['repositoryUrl'],
82
- root_folder_url: repository_info['rootFolderUrl'] }
83
- end
84
- @@url_cache[repository_id]
85
- end
86
-
87
- def check(hash)
88
- check_in(hash, :includeRelationships, [:none, :source, :target, :both])
89
- end
90
-
91
- def check_in(hash, key, arr)
92
- value = hash[key]
93
- unless value.nil?
94
- unless arr.include?(value)
95
- raise ArgumentError, "#{key} must be one of #{arr}."
96
- end
97
- end
98
- end
99
-
100
- def transform_hash(hash)
101
- if hash.has_key?(:content)
102
- content = hash.delete(:content)
103
- hash[:content] = UploadIO.new(content[:stream],
104
- content[:mime_type],
105
- content[:filename])
106
- end
107
- if hash.has_key?(:properties)
108
- props = hash.delete(:properties)
109
- if props.is_a?(Hash)
110
- props.each_with_index do |(id, value), index|
111
- value = value.to_time if value.is_a?(Date) or value.is_a?(DateTime)
112
- value = (value.to_f * 1000).to_i if value.is_a?(Time)
113
- if value.is_a?(Array)
114
- hash.merge!("propertyId[#{index}]" => id)
115
- value.each_with_index { |v, idx|
116
- hash.merge!("propertyValue[#{index}][#{idx}]" => value[idx])
117
- }
118
- else
119
- hash.merge!("propertyId[#{index}]" => id,
120
- "propertyValue[#{index}]" => value)
121
- end
122
- end
123
- end
124
- end
125
- hash
126
- end
127
-
128
- class Basement
129
-
130
- def initialize(user, pass)
131
- @username = user
132
- @password = pass
133
- end
134
-
135
- def get(params)
136
- Typhoeus::Request.new(
137
- params[:url],
138
- userpwd: "#{@username}:#{@password}",
139
- method: :get,
140
- body: params[:body],
141
- params: params[:query],
142
- headers: params[:headers],
143
- followlocation: true
144
- ).run
145
- end
146
-
147
- def post(params)
148
- Typhoeus::Request.new(
149
- params[:url],
150
- userpwd: "#{@username}:#{@password}",
151
- method: :post,
152
- body: params[:body],
153
- params: params[:query],
154
- headers: params[:headers]
155
- ).run
156
- end
157
-
158
- def multipart_post(url, options, headers)
159
- url = URI.parse(url)
160
- req = Net::HTTP::Post::Multipart.new(url.path, options)
161
- headers.each {|key, value| req[key] = value }
162
- req.basic_auth @username, @password unless @username.nil?
163
- opts = url.scheme == 'https' ? { use_ssl: true , verify_mode: OpenSSL::SSL::VERIFY_NONE } : {}
164
- Net::HTTP.start(url.host, url.port, opts) { |http| http.request(req) }
165
- end
166
- end
167
- end
168
- end
169
- end
170
- end
@@ -1,103 +0,0 @@
1
- =begin
2
- Code taken mostly from ActiveRecord::Cache
3
- Copyright (c) 2005-2011 David Heinemeier Hansson
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
-
24
- =end
25
- require 'digest/md5'
26
- module SimpleCache
27
- #TODO: add a super-class and implement FileSystemCache
28
- class MemoryCache
29
-
30
- attr_reader :cache_size
31
-
32
- def initialize(options = {})
33
- @cache = {}
34
- @cache_size = 0
35
- @key_access = {}
36
- @max_size = options[:max_size] || 32 * 1024 #32 megabytes
37
- @timeout = options[:timeout] || 60*30 #30 minutes
38
- end
39
-
40
- def encode(key)
41
- Digest::MD5.hexdigest key
42
- end
43
-
44
- def delete(key)
45
- entry = @cache.delete key
46
- @key_access.delete key
47
- @cache_size -= entry.size
48
- end
49
-
50
- def [](key)
51
- key = encode(key)
52
- entry = @cache[key]
53
- if entry
54
- @key_access[key] = Time.now.to_f
55
- else
56
- @key_access.delete key
57
- end
58
- entry
59
- end
60
-
61
- def []=(key, value)
62
- key = encode(key)
63
- old_entry = @cache[key]
64
- @cache_size -= old_entry.size if old_entry
65
- @key_access[key] = Time.now.to_f
66
- @cache[key] = value
67
- @cache_size += value.to_s.size
68
- prune if @cache_size > @max_size
69
- end
70
-
71
- def has_key?(key)
72
- !!@cache[encode(key)]
73
- end
74
-
75
- def prune
76
- # first, the obvious cleanup
77
- @cache.keys.each do |key|
78
- delete(key) if stale? key
79
- end
80
-
81
- # now, try to leave it a 3/4 of it's capacity
82
- target_size = 0.75 * @max_size
83
-
84
- # delete the older entries
85
- sorted_keys = @key_access.keys.sort{|a,b| @key_access[a].to_f <=> @key_access[b].to_f}
86
- sorted_keys.each do |key|
87
- return if @cache_size <= target_size
88
- delete key
89
- end
90
- end
91
-
92
- def stale?(key)
93
- (Time.now.to_f - @key_access[key]) > @timeout.to_f
94
- end
95
-
96
- def clear
97
- @cache = {}
98
- @cache_size = 0
99
- @key_access = {}
100
- end
101
-
102
- end
103
- end
@@ -1,22 +0,0 @@
1
- module YACCL
2
- module MultiFilingServices
3
- def add_object_to_folder(repository_id, cmis_object_id, folder_id, all_versions, succinct=false)
4
- required = {succinct: succinct,
5
- cmisaction: 'addObjectToFolder',
6
- repositoryId: repository_id,
7
- objectId: cmis_object_id,
8
- folderId: folder_id}
9
- optional = {allVersions: all_versions}
10
- perform_request(required, optional)
11
- end
12
-
13
- def remove_object_from_folder(repository_id, cmis_object_id, folder_id, succinct=false)
14
- required = {succinct: succinct,
15
- repositoryId: repository_id,
16
- cmisaction: 'removeObjectFromFolder',
17
- objectId: cmis_object_id}
18
- optional = {folderId: folder_id}
19
- perform_request(required, optional)
20
- end
21
- end
22
- end