Class: CmisServer::CmisObject
- Inherits:
-
Object
- Object
- CmisServer::CmisObject
show all
- Defined in:
- lib/cmis_server/cmis_object.rb
Defined Under Namespace
Classes: InvalidType
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(type:, properties: {}, secondary_types: []) ⇒ CmisObject
Returns a new instance of CmisObject.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/cmis_server/cmis_object.rb', line 11
def initialize(type:, properties: {}, secondary_types: [])
self.type = type
@secondary_types = []
initialize_properties
secondary_types.each do |secondary_type|
add_secondary_type(secondary_type)
end
properties.to_h.each do |property, value|
self.send(property.to_s.gsub(/[^0-9a-z]/i, '_').underscore+"=", value)
end
end
|
Instance Attribute Details
#properties ⇒ Object
Returns the value of attribute properties.
6
7
8
|
# File 'lib/cmis_server/cmis_object.rb', line 6
def properties
@properties
end
|
#secondary_types ⇒ Object
Returns the value of attribute secondary_types.
7
8
9
|
# File 'lib/cmis_server/cmis_object.rb', line 7
def secondary_types
@secondary_types
end
|
#type ⇒ Object
Returns the value of attribute type.
5
6
7
|
# File 'lib/cmis_server/cmis_object.rb', line 5
def type
@type
end
|
Instance Method Details
#add_secondary_type(secondary_type) ⇒ Object
CMIS 1.1: Méthodes pour gérer les types secondaires
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/cmis_server/cmis_object.rb', line 35
def add_secondary_type(secondary_type)
unless secondary_type.base_id == 'cmis:secondary'
raise InvalidType.new("#{secondary_type.id} is not a secondary type")
end
if has_secondary_type?(secondary_type.id)
raise InvalidType.new("#{secondary_type.id} is already added")
end
@secondary_types << secondary_type
add_secondary_type_properties(secondary_type)
update_secondary_type_ids
secondary_type
end
|
#all_property_definitions ⇒ Object
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/cmis_server/cmis_object.rb', line 106
def all_property_definitions
all_defs = type.property_definitions.to_a
@secondary_types.each do |secondary_type|
all_defs.concat(secondary_type.property_definitions.to_a)
end
all_defs
end
|
#copy_properties_values_of(object) ⇒ Object
30
31
32
|
# File 'lib/cmis_server/cmis_object.rb', line 30
def copy_properties_values_of object
self.properties.each{|_k,property| property.value=object.send(property.property_definition.getter_method_name)}
end
|
#has_secondary_type?(type_id) ⇒ Boolean
77
78
79
|
# File 'lib/cmis_server/cmis_object.rb', line 77
def has_secondary_type?(type_id)
@secondary_types.any? { |st| st.id == type_id }
end
|
#remove_secondary_type(type_id) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/cmis_server/cmis_object.rb', line 58
def remove_secondary_type(type_id)
secondary_type = @secondary_types.find { |st| st.id == type_id }
unless secondary_type
raise InvalidType.new("#{type_id} is not a secondary type of this object")
end
@secondary_types.delete(secondary_type)
remove_secondary_type_properties(secondary_type)
update_secondary_type_ids
true
end
|
#save ⇒ Object
100
101
102
103
104
|
# File 'lib/cmis_server/cmis_object.rb', line 100
def save
true
end
|
#to_renderable_object ⇒ Object
26
27
28
|
# File 'lib/cmis_server/cmis_object.rb', line 26
def to_renderable_object
CmisServer::RenderableObject.new(base_object: self)
end
|
#update_properties(properties_hash) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/cmis_server/cmis_object.rb', line 81
def update_properties(properties_hash)
properties_hash.each do |prop_id, value|
if @properties.key?(prop_id)
@properties[prop_id].value = value
else
property_def = find_property_definition(prop_id)
if property_def && property_def.owning_type && property_def.owning_type.base_id == 'cmis:secondary'
add_secondary_type(property_def.owning_type)
@properties[prop_id].value = value
else
raise ArgumentError, "Property #{prop_id} does not exist for this object"
end
end
end
end
|