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


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

#repositoryObject

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(opts = {}) ⇒ Object


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

def create(opts = {})
  opts.symbolize_keys!

  type_hash = to_hash
  type_hash.merge!(opts.delete(:extensions) || {})

  result = server.execute!({ cmisaction: 'createType',
                             repositoryId: repository.id,
                             type: JSON.generate(type_hash) }, opts)

  Type.new(result, repository)
end

#delete(opts = {}) ⇒ Object


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

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

#document_type?Boolean

Returns:

  • (Boolean)

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

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

#folder_type?Boolean

Returns:

  • (Boolean)

76
77
78
# File 'lib/cmis/type.rb', line 76

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

#item_type?Boolean

Returns:

  • (Boolean)

88
89
90
# File 'lib/cmis/type.rb', line 88

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

#new_objectObject


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/cmis/type.rb', line 92

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)

84
85
86
# File 'lib/cmis/type.rb', line 84

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

#relationship_type?Boolean

Returns:

  • (Boolean)

80
81
82
# File 'lib/cmis/type.rb', line 80

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

#to_hashObject


111
112
113
# File 'lib/cmis/type.rb', line 111

def to_hash
  @hash
end

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


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cmis/type.rb', line 46

def update(changed_property_defs, opts = {})
  changed_property_defs.map!(&:deep_stringify_keys)
  opts.symbolize_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
  hash.merge!(opts.delete(:extensions) || {})

  result = server.execute!({ cmisaction: 'updateType',
                             repositoryId: repository.id,
                             type: JSON.generate(hash) }, opts)

  Type.new(result, repository)
end