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.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cmis/type.rb', line 9 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.underscore};@hash['#{key}'];end" self.class.class_eval "def #{key.underscore}=(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.
7 8 9 |
# File 'lib/cmis/type.rb', line 7 def repository @repository end |
Instance Method Details
#add_property_definition(property) ⇒ Object
30 31 32 33 |
# File 'lib/cmis/type.rb', line 30 def add_property_definition(property) property.stringify_keys! property_definitions[property['id']] = property end |
#create ⇒ Object
35 36 37 |
# File 'lib/cmis/type.rb', line 35 def create repository.create_type(self) end |
#delete(opts = {}) ⇒ Object
57 58 59 60 61 |
# File 'lib/cmis/type.rb', line 57 def delete(opts = {}) server.execute!({ cmisaction: 'deleteType', repositoryId: repository.id, typeId: id }, opts) end |
#document_type? ⇒ Boolean
63 64 65 |
# File 'lib/cmis/type.rb', line 63 def document_type? base_id == 'cmis:document' end |
#folder_type? ⇒ Boolean
67 68 69 |
# File 'lib/cmis/type.rb', line 67 def folder_type? base_id == 'cmis:folder' end |
#item_type? ⇒ Boolean
79 80 81 |
# File 'lib/cmis/type.rb', line 79 def item_type? base_id == 'cmis:item' end |
#new_object ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/cmis/type.rb', line 83 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
75 76 77 |
# File 'lib/cmis/type.rb', line 75 def policy_type? base_id == 'cmis:policy' end |
#relationship_type? ⇒ Boolean
71 72 73 |
# File 'lib/cmis/type.rb', line 71 def relationship_type? base_id == 'cmis:relationship' end |
#to_hash ⇒ Object
102 103 104 |
# File 'lib/cmis/type.rb', line 102 def to_hash @hash end |
#update(changed_property_defs, opts = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cmis/type.rb', line 39 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 |