Class: CMIS::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/cmis/type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, repository) ⇒ Type

Returns a new instance of Type.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cmis/type.rb', line 5

def initialize(hash, repository)
  @repository = repository
  @hash = hash.with_indifferent_access

  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|
    class_eval "def #{key.underscore};@hash['#{key}'];end"
    class_eval "def #{key.underscore}=(value);@hash['#{key}']=value;end"
  end

  @hash['propertyDefinitions'] ||= ActiveSupport::HashWithIndifferentAccess.new
  @hash['propertyDefinitions'].each do |key, value|
    @hash['propertyDefinitions'][key] = PropertyDefinition.new(value)
  end
end

Instance Attribute Details

#repositoryObject

Returns the value of attribute repository.



3
4
5
# File 'lib/cmis/type.rb', line 3

def repository
  @repository
end

Instance Method Details

#add_property_definition(property) ⇒ Object



26
27
28
# File 'lib/cmis/type.rb', line 26

def add_property_definition(property)
  property_definitions[property[:id]] = property
end

#createObject



30
31
32
# File 'lib/cmis/type.rb', line 30

def create
  repository.create_type(self)
end

#delete(opts = {}) ⇒ Object



50
51
52
53
54
# File 'lib/cmis/type.rb', line 50

def delete(opts = {})
  connection.execute!({ cmisaction: 'deleteType',
                        repositoryId: repository.id,
                        typeId: id }, opts)
end

#document_type?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/cmis/type.rb', line 56

def document_type?
  base_id == 'cmis:document'
end

#folder_type?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/cmis/type.rb', line 60

def folder_type?
  base_id == 'cmis:folder'
end

#item_type?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/cmis/type.rb', line 72

def item_type?
  base_id == 'cmis:item'
end

#new_objectObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/cmis/type.rb', line 76

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

Returns:

  • (Boolean)


68
69
70
# File 'lib/cmis/type.rb', line 68

def policy_type?
  base_id == 'cmis:policy'
end

#relationship_type?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/cmis/type.rb', line 64

def relationship_type?
  base_id == 'cmis:relationship'
end

#to_hashObject



95
96
97
# File 'lib/cmis/type.rb', line 95

def to_hash
  @hash
end

#update(changed_property_defs, opts = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cmis/type.rb', line 34

def update(changed_property_defs, opts = {})
  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 = connection.execute!({ cmisaction: 'updateType',
                                 repositoryId: repository.id,
                                 type: JSON.generate(hash) }, opts)

  Type.new(result, repository)
end