Class: CMIS::Type
- Inherits:
-
Object
- Object
- CMIS::Type
- Defined in:
- lib/cmis/type.rb
Instance Attribute Summary collapse
-
#repository ⇒ Object
Returns the value of attribute repository.
Instance Method Summary collapse
- #add_property_definition(property) ⇒ Object
- #create ⇒ Object
- #delete(opts = {}) ⇒ Object
- #document_type? ⇒ Boolean
- #folder_type? ⇒ Boolean
-
#initialize(hash, repository) ⇒ Type
constructor
A new instance of Type.
- #item_type? ⇒ Boolean
- #new_object ⇒ Object
- #policy_type? ⇒ Boolean
- #relationship_type? ⇒ Boolean
- #to_hash ⇒ Object
- #update(changed_property_defs, opts = {}) ⇒ Object
Constructor Details
#initialize(hash, repository) ⇒ Type
Returns a new instance of Type.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cmis/type.rb', line 7 def initialize(hash, repository) @repository = repository @hash = hash.deep_stringify_keys properties = %w( id localName localNamespace queryName displayName baseId parentId description creatable fileable queryable controllablePolicy controllableACL fulltextIndexed includedInSupertypeQuery propertyDefinitions versionable contentStreamAllowed allowedSourceTypes allowedTargetTypes ) properties.each do |key| self.class.class_eval "def #{key.as_ruby_property};@hash['#{key}'];end" self.class.class_eval "def #{key.as_ruby_property}=(value);@hash['#{key}']=value;end" end @hash['propertyDefinitions'] ||= {} @hash['propertyDefinitions'].each do |key, value| @hash['propertyDefinitions'][key] = PropertyDefinition.new(value) end end |
Instance Attribute Details
#repository ⇒ Object
Returns the value of attribute repository.
5 6 7 |
# File 'lib/cmis/type.rb', line 5 def repository @repository end |
Instance Method Details
#add_property_definition(property) ⇒ Object
28 29 30 31 |
# File 'lib/cmis/type.rb', line 28 def add_property_definition(property) property.stringify_keys! property_definitions[property['id']] = property end |
#create ⇒ Object
33 34 35 |
# File 'lib/cmis/type.rb', line 33 def create repository.create_type(self) end |
#delete(opts = {}) ⇒ Object
55 56 57 58 59 |
# File 'lib/cmis/type.rb', line 55 def delete(opts = {}) server.execute!({ cmisaction: 'deleteType', repositoryId: repository.id, typeId: id }, opts) end |
#document_type? ⇒ Boolean
61 62 63 |
# File 'lib/cmis/type.rb', line 61 def document_type? base_id == 'cmis:document' end |
#folder_type? ⇒ Boolean
65 66 67 |
# File 'lib/cmis/type.rb', line 65 def folder_type? base_id == 'cmis:folder' end |
#item_type? ⇒ Boolean
77 78 79 |
# File 'lib/cmis/type.rb', line 77 def item_type? base_id == 'cmis:item' end |
#new_object ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/cmis/type.rb', line 81 def new_object object = case base_id when 'cmis:document' Document.new({}, repository) when 'cmis:folder' Folder.new({}, repository) when 'cmis:relationship' Relationship.new({}, repository) when 'cmis:policy' Policy.new({}, repository) when 'cmis:item' Item.new({}, repository) else raise "Unsupported base type: #{base_id}" end object.object_type_id = id object end |
#policy_type? ⇒ Boolean
73 74 75 |
# File 'lib/cmis/type.rb', line 73 def policy_type? base_id == 'cmis:policy' end |
#relationship_type? ⇒ Boolean
69 70 71 |
# File 'lib/cmis/type.rb', line 69 def relationship_type? base_id == 'cmis:relationship' end |
#to_hash ⇒ Object
100 101 102 |
# File 'lib/cmis/type.rb', line 100 def to_hash @hash end |
#update(changed_property_defs, opts = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cmis/type.rb', line 37 def update(changed_property_defs, opts = {}) changed_property_defs.map!(&:deep_stringify_keys) new_defs = changed_property_defs.map(&:to_hash).reduce({}) do |result, element| result[element['id']] = element result end hash = to_hash hash['propertyDefinitions'] = new_defs result = server.execute!({ cmisaction: 'updateType', repositoryId: repository.id, type: JSON.generate(hash) }, opts) Type.new(result, repository) end |