microsoft_graph 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +11 -11
- data/.rspec +2 -2
- data/.travis.yml +4 -4
- data/Gemfile +4 -4
- data/LICENSE +10 -10
- data/README.md +99 -98
- data/Rakefile +7 -7
- data/data/metadata_v1.0.xml +1686 -1686
- data/integration_spec/integration_spec_helper.rb +18 -18
- data/integration_spec/live_spec.rb +180 -180
- data/lib/microsoft_graph.rb +35 -35
- data/lib/microsoft_graph/base.rb +110 -110
- data/lib/microsoft_graph/base_entity.rb +152 -152
- data/lib/microsoft_graph/cached_metadata_directory.rb +3 -3
- data/lib/microsoft_graph/class_builder.rb +217 -217
- data/lib/microsoft_graph/collection.rb +95 -95
- data/lib/microsoft_graph/collection_association.rb +232 -232
- data/lib/microsoft_graph/errors.rb +6 -6
- data/lib/microsoft_graph/version.rb +3 -3
- data/lib/odata.rb +49 -49
- data/lib/odata/entity_set.rb +20 -20
- data/lib/odata/errors.rb +18 -18
- data/lib/odata/navigation_property.rb +30 -30
- data/lib/odata/operation.rb +17 -17
- data/lib/odata/property.rb +38 -38
- data/lib/odata/request.rb +49 -49
- data/lib/odata/service.rb +279 -279
- data/lib/odata/singleton.rb +20 -20
- data/lib/odata/type.rb +25 -25
- data/lib/odata/types/collection_type.rb +30 -30
- data/lib/odata/types/complex_type.rb +19 -19
- data/lib/odata/types/entity_type.rb +33 -33
- data/lib/odata/types/enum_type.rb +37 -37
- data/lib/odata/types/primitive_type.rb +12 -12
- data/lib/odata/types/primitive_types/binary_type.rb +15 -15
- data/lib/odata/types/primitive_types/boolean_type.rb +15 -15
- data/lib/odata/types/primitive_types/date_time_offset_type.rb +15 -15
- data/lib/odata/types/primitive_types/date_type.rb +23 -23
- data/lib/odata/types/primitive_types/double_type.rb +16 -16
- data/lib/odata/types/primitive_types/guid_type.rb +24 -24
- data/lib/odata/types/primitive_types/int_16_type.rb +19 -19
- data/lib/odata/types/primitive_types/int_32_type.rb +15 -15
- data/lib/odata/types/primitive_types/int_64_type.rb +15 -15
- data/lib/odata/types/primitive_types/stream_type.rb +15 -15
- data/lib/odata/types/primitive_types/string_type.rb +15 -15
- data/microsoft_graph-0.1.2.gem +0 -0
- data/microsoft_graph.gemspec +31 -31
- data/tasks/update_metadata.rb +17 -17
- metadata +6 -6
- data/microsoft_graph-0.1.0.gem +0 -0
@@ -1,3 +1,3 @@
|
|
1
|
-
class MicrosoftGraph
|
2
|
-
CACHED_METADATA_DIRECTORY = File.realpath(File.join(__FILE__, "../../../data/"))
|
3
|
-
end
|
1
|
+
class MicrosoftGraph
|
2
|
+
CACHED_METADATA_DIRECTORY = File.realpath(File.join(__FILE__, "../../../data/"))
|
3
|
+
end
|
@@ -1,217 +1,217 @@
|
|
1
|
-
class MicrosoftGraph
|
2
|
-
class ClassBuilder
|
3
|
-
@@loaded = false
|
4
|
-
|
5
|
-
def self.load!(service)
|
6
|
-
if !@@loaded
|
7
|
-
@service_namespace = service.namespace
|
8
|
-
service.entity_types.each do |entity_type|
|
9
|
-
create_class! entity_type
|
10
|
-
end
|
11
|
-
|
12
|
-
service.complex_types.each do |complex_type|
|
13
|
-
create_class! complex_type
|
14
|
-
end
|
15
|
-
|
16
|
-
service.entity_sets.each do |entity_set|
|
17
|
-
add_graph_association! entity_set
|
18
|
-
end
|
19
|
-
|
20
|
-
service.actions.each do |action|
|
21
|
-
add_action_method! action
|
22
|
-
end
|
23
|
-
|
24
|
-
service.functions.each do |function|
|
25
|
-
add_function_method! function
|
26
|
-
end
|
27
|
-
|
28
|
-
service.singletons.each do |singleton|
|
29
|
-
class_name = classify(singleton.type_name)
|
30
|
-
MicrosoftGraph.instance_eval do
|
31
|
-
resource_name = singleton.name
|
32
|
-
define_method(OData.convert_to_snake_case(resource_name)) do
|
33
|
-
MicrosoftGraph
|
34
|
-
.const_get(class_name)
|
35
|
-
.new(
|
36
|
-
graph: self,
|
37
|
-
resource_name: resource_name,
|
38
|
-
parent: self
|
39
|
-
).tap(&:fetch)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
MicrosoftGraph.instance_eval do
|
45
|
-
define_method(:navigation_properties) do
|
46
|
-
service.entity_sets
|
47
|
-
.concat(service.singletons)
|
48
|
-
.map { |navigation_property|
|
49
|
-
[navigation_property.name.to_sym, navigation_property]
|
50
|
-
}.to_h
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
@@loaded = true
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.loaded?
|
59
|
-
@@loaded
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def remove_service_namespace(name)
|
65
|
-
name.gsub("#{@service_namespace}.", "")
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.create_class!(type)
|
69
|
-
superklass = get_superklass(type)
|
70
|
-
klass = MicrosoftGraph.const_set(classify(type.name), Class.new(superklass))
|
71
|
-
klass.const_set("ODATA_TYPE", type)
|
72
|
-
klass.instance_eval do
|
73
|
-
def self.odata_type
|
74
|
-
const_get("ODATA_TYPE")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
create_properties(klass, type)
|
78
|
-
create_navigation_properties(klass, type) if type.respond_to? :navigation_properties
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.add_graph_association!(entity_set)
|
82
|
-
klass = get_namespaced_class(entity_set.member_type)
|
83
|
-
resource_name = entity_set.name.gsub("#{@service_namespace}.", "")
|
84
|
-
odata_collection =
|
85
|
-
OData::CollectionType.new(member_type: klass.odata_type, name: entity_set.name)
|
86
|
-
MicrosoftGraph.send(:define_method, resource_name) do
|
87
|
-
@association_collections[entity_set.name] ||=
|
88
|
-
MicrosoftGraph::CollectionAssociation
|
89
|
-
.new(
|
90
|
-
type: odata_collection,
|
91
|
-
resource_name: resource_name,
|
92
|
-
parent: self
|
93
|
-
)
|
94
|
-
.tap do |collection|
|
95
|
-
collection.graph = self
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def self.create_properties(klass, type)
|
101
|
-
property_map = type.properties.map { |property|
|
102
|
-
define_getter_and_setter(klass, property)
|
103
|
-
[
|
104
|
-
OData.convert_to_snake_case(property.name).to_sym,
|
105
|
-
property
|
106
|
-
]
|
107
|
-
}.to_h
|
108
|
-
|
109
|
-
klass.class_eval do
|
110
|
-
define_method(:properties) do
|
111
|
-
super().merge(property_map)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def self.define_getter_and_setter(klass, property)
|
117
|
-
klass.class_eval do
|
118
|
-
property_name = OData.convert_to_snake_case(property.name)
|
119
|
-
define_method(property_name.to_sym) do
|
120
|
-
get(property_name.to_sym)
|
121
|
-
end
|
122
|
-
define_method("#{property_name}=".to_sym) do |value|
|
123
|
-
set(property_name.to_sym, value)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def self.create_navigation_properties(klass, type)
|
129
|
-
klass.class_eval do
|
130
|
-
type.navigation_properties.each do |navigation_property|
|
131
|
-
navigation_property_name = OData.convert_to_snake_case(navigation_property.name).to_sym
|
132
|
-
define_method(navigation_property_name.to_sym) do
|
133
|
-
get_navigation_property(navigation_property_name.to_sym)
|
134
|
-
end
|
135
|
-
unless navigation_property.collection?
|
136
|
-
define_method("#{navigation_property_name}=".to_sym) do |value|
|
137
|
-
set_navigation_property(navigation_property_name.to_sym, value)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
define_method(:navigation_properties) do
|
143
|
-
type.navigation_properties.map { |navigation_property|
|
144
|
-
[
|
145
|
-
OData.convert_to_snake_case(navigation_property.name).to_sym,
|
146
|
-
navigation_property
|
147
|
-
]
|
148
|
-
}.to_h
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def self.add_function_method!(function)
|
154
|
-
klass = get_namespaced_class(function.binding_type.name)
|
155
|
-
klass.class_eval do
|
156
|
-
define_method(OData.convert_to_snake_case(function.name).to_sym) do |params={}|
|
157
|
-
raise NoAssociationError unless parent
|
158
|
-
raise_no_graph_error! unless graph
|
159
|
-
function_params = params.map do |param_key, param_value|
|
160
|
-
"#{OData.convert_to_camel_case(param_key)}='#{param_value}'"
|
161
|
-
end
|
162
|
-
response = graph.service.get("#{path}/microsoft.graph.#{function.name}(#{function_params.join(',')})")
|
163
|
-
if function.return_type
|
164
|
-
if function.return_type.collection?
|
165
|
-
Collection.new(function.return_type, response[:attributes]['value'])
|
166
|
-
else
|
167
|
-
ClassBuilder.get_namespaced_class(function.return_type.name).new(attributes: response[:attributes]['value'])
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
def self.add_action_method!(action)
|
175
|
-
klass = get_namespaced_class(action.binding_type.name)
|
176
|
-
klass.class_eval do
|
177
|
-
define_method(OData.convert_to_snake_case(action.name).to_sym) do |args={}|
|
178
|
-
raise NoAssociationError unless parent
|
179
|
-
raise_no_graph_error! unless graph
|
180
|
-
response = graph.service.post("#{path}/#{action.name}", OData.convert_keys_to_camel_case(args).to_json)
|
181
|
-
if action.return_type
|
182
|
-
if action.return_type.collection?
|
183
|
-
Collection.new(action.return_type, response['value'])
|
184
|
-
else
|
185
|
-
ClassBuilder.get_namespaced_class(action.return_type.name).new(attributes: response['value'])
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
def self.classify(name)
|
193
|
-
raw_name = name.gsub("#{@service_namespace}.", "")
|
194
|
-
raw_name.to_s.slice(0, 1).capitalize + raw_name.to_s.slice(1..-1)
|
195
|
-
end
|
196
|
-
|
197
|
-
def self.get_namespaced_class(property_name)
|
198
|
-
klass_name = classify(property_name)
|
199
|
-
klass = begin
|
200
|
-
MicrosoftGraph.const_get(klass_name) if MicrosoftGraph.const_defined?(klass_name)
|
201
|
-
rescue NameError
|
202
|
-
return false
|
203
|
-
end
|
204
|
-
klass && MicrosoftGraph::BaseEntity != klass.superclass && klass
|
205
|
-
end
|
206
|
-
|
207
|
-
def self.get_superklass(type)
|
208
|
-
if type.base_type.nil?
|
209
|
-
(type.class == OData::ComplexType) ?
|
210
|
-
MicrosoftGraph::Base :
|
211
|
-
MicrosoftGraph::BaseEntity
|
212
|
-
else
|
213
|
-
Object.const_get("MicrosoftGraph::" + classify(type.base_type))
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
1
|
+
class MicrosoftGraph
|
2
|
+
class ClassBuilder
|
3
|
+
@@loaded = false
|
4
|
+
|
5
|
+
def self.load!(service)
|
6
|
+
if !@@loaded
|
7
|
+
@service_namespace = service.namespace
|
8
|
+
service.entity_types.each do |entity_type|
|
9
|
+
create_class! entity_type
|
10
|
+
end
|
11
|
+
|
12
|
+
service.complex_types.each do |complex_type|
|
13
|
+
create_class! complex_type
|
14
|
+
end
|
15
|
+
|
16
|
+
service.entity_sets.each do |entity_set|
|
17
|
+
add_graph_association! entity_set
|
18
|
+
end
|
19
|
+
|
20
|
+
service.actions.each do |action|
|
21
|
+
add_action_method! action
|
22
|
+
end
|
23
|
+
|
24
|
+
service.functions.each do |function|
|
25
|
+
add_function_method! function
|
26
|
+
end
|
27
|
+
|
28
|
+
service.singletons.each do |singleton|
|
29
|
+
class_name = classify(singleton.type_name)
|
30
|
+
MicrosoftGraph.instance_eval do
|
31
|
+
resource_name = singleton.name
|
32
|
+
define_method(OData.convert_to_snake_case(resource_name)) do
|
33
|
+
MicrosoftGraph
|
34
|
+
.const_get(class_name)
|
35
|
+
.new(
|
36
|
+
graph: self,
|
37
|
+
resource_name: resource_name,
|
38
|
+
parent: self
|
39
|
+
).tap(&:fetch)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
MicrosoftGraph.instance_eval do
|
45
|
+
define_method(:navigation_properties) do
|
46
|
+
service.entity_sets
|
47
|
+
.concat(service.singletons)
|
48
|
+
.map { |navigation_property|
|
49
|
+
[navigation_property.name.to_sym, navigation_property]
|
50
|
+
}.to_h
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
@@loaded = true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.loaded?
|
59
|
+
@@loaded
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def remove_service_namespace(name)
|
65
|
+
name.gsub("#{@service_namespace}.", "")
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.create_class!(type)
|
69
|
+
superklass = get_superklass(type)
|
70
|
+
klass = MicrosoftGraph.const_set(classify(type.name), Class.new(superklass))
|
71
|
+
klass.const_set("ODATA_TYPE", type)
|
72
|
+
klass.instance_eval do
|
73
|
+
def self.odata_type
|
74
|
+
const_get("ODATA_TYPE")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
create_properties(klass, type)
|
78
|
+
create_navigation_properties(klass, type) if type.respond_to? :navigation_properties
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.add_graph_association!(entity_set)
|
82
|
+
klass = get_namespaced_class(entity_set.member_type)
|
83
|
+
resource_name = entity_set.name.gsub("#{@service_namespace}.", "")
|
84
|
+
odata_collection =
|
85
|
+
OData::CollectionType.new(member_type: klass.odata_type, name: entity_set.name)
|
86
|
+
MicrosoftGraph.send(:define_method, resource_name) do
|
87
|
+
@association_collections[entity_set.name] ||=
|
88
|
+
MicrosoftGraph::CollectionAssociation
|
89
|
+
.new(
|
90
|
+
type: odata_collection,
|
91
|
+
resource_name: resource_name,
|
92
|
+
parent: self
|
93
|
+
)
|
94
|
+
.tap do |collection|
|
95
|
+
collection.graph = self
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.create_properties(klass, type)
|
101
|
+
property_map = type.properties.map { |property|
|
102
|
+
define_getter_and_setter(klass, property)
|
103
|
+
[
|
104
|
+
OData.convert_to_snake_case(property.name).to_sym,
|
105
|
+
property
|
106
|
+
]
|
107
|
+
}.to_h
|
108
|
+
|
109
|
+
klass.class_eval do
|
110
|
+
define_method(:properties) do
|
111
|
+
super().merge(property_map)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.define_getter_and_setter(klass, property)
|
117
|
+
klass.class_eval do
|
118
|
+
property_name = OData.convert_to_snake_case(property.name)
|
119
|
+
define_method(property_name.to_sym) do
|
120
|
+
get(property_name.to_sym)
|
121
|
+
end
|
122
|
+
define_method("#{property_name}=".to_sym) do |value|
|
123
|
+
set(property_name.to_sym, value)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.create_navigation_properties(klass, type)
|
129
|
+
klass.class_eval do
|
130
|
+
type.navigation_properties.each do |navigation_property|
|
131
|
+
navigation_property_name = OData.convert_to_snake_case(navigation_property.name).to_sym
|
132
|
+
define_method(navigation_property_name.to_sym) do
|
133
|
+
get_navigation_property(navigation_property_name.to_sym)
|
134
|
+
end
|
135
|
+
unless navigation_property.collection?
|
136
|
+
define_method("#{navigation_property_name}=".to_sym) do |value|
|
137
|
+
set_navigation_property(navigation_property_name.to_sym, value)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
define_method(:navigation_properties) do
|
143
|
+
type.navigation_properties.map { |navigation_property|
|
144
|
+
[
|
145
|
+
OData.convert_to_snake_case(navigation_property.name).to_sym,
|
146
|
+
navigation_property
|
147
|
+
]
|
148
|
+
}.to_h
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def self.add_function_method!(function)
|
154
|
+
klass = get_namespaced_class(function.binding_type.name)
|
155
|
+
klass.class_eval do
|
156
|
+
define_method(OData.convert_to_snake_case(function.name).to_sym) do |params={}|
|
157
|
+
raise NoAssociationError unless parent
|
158
|
+
raise_no_graph_error! unless graph
|
159
|
+
function_params = params.map do |param_key, param_value|
|
160
|
+
"#{OData.convert_to_camel_case(param_key)}='#{param_value}'"
|
161
|
+
end
|
162
|
+
response = graph.service.get("#{path}/microsoft.graph.#{function.name}(#{function_params.join(',')})")
|
163
|
+
if function.return_type
|
164
|
+
if function.return_type.collection?
|
165
|
+
Collection.new(function.return_type, response[:attributes]['value'])
|
166
|
+
else
|
167
|
+
ClassBuilder.get_namespaced_class(function.return_type.name).new(attributes: response[:attributes]['value'])
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def self.add_action_method!(action)
|
175
|
+
klass = get_namespaced_class(action.binding_type.name)
|
176
|
+
klass.class_eval do
|
177
|
+
define_method(OData.convert_to_snake_case(action.name).to_sym) do |args={}|
|
178
|
+
raise NoAssociationError unless parent
|
179
|
+
raise_no_graph_error! unless graph
|
180
|
+
response = graph.service.post("#{path}/#{action.name}", OData.convert_keys_to_camel_case(args).to_json)
|
181
|
+
if action.return_type
|
182
|
+
if action.return_type.collection?
|
183
|
+
Collection.new(action.return_type, response['value'])
|
184
|
+
else
|
185
|
+
ClassBuilder.get_namespaced_class(action.return_type.name).new(attributes: response['value'])
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def self.classify(name)
|
193
|
+
raw_name = name.gsub("#{@service_namespace}.", "")
|
194
|
+
raw_name.to_s.slice(0, 1).capitalize + raw_name.to_s.slice(1..-1)
|
195
|
+
end
|
196
|
+
|
197
|
+
def self.get_namespaced_class(property_name)
|
198
|
+
klass_name = classify(property_name)
|
199
|
+
klass = begin
|
200
|
+
MicrosoftGraph.const_get(klass_name) if MicrosoftGraph.const_defined?(klass_name)
|
201
|
+
rescue NameError
|
202
|
+
return false
|
203
|
+
end
|
204
|
+
klass && MicrosoftGraph::BaseEntity != klass.superclass && klass
|
205
|
+
end
|
206
|
+
|
207
|
+
def self.get_superklass(type)
|
208
|
+
if type.base_type.nil?
|
209
|
+
(type.class == OData::ComplexType) ?
|
210
|
+
MicrosoftGraph::Base :
|
211
|
+
MicrosoftGraph::BaseEntity
|
212
|
+
else
|
213
|
+
Object.const_get("MicrosoftGraph::" + classify(type.base_type))
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
@@ -1,95 +1,95 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
|
3
|
-
class MicrosoftGraph
|
4
|
-
class Collection
|
5
|
-
include Enumerable
|
6
|
-
extend Forwardable
|
7
|
-
|
8
|
-
attr_accessor :graph
|
9
|
-
|
10
|
-
def_delegators :values, :size, :length, :include?, :empty?, :[]
|
11
|
-
|
12
|
-
def initialize(type, initial_values = [])
|
13
|
-
@type = type
|
14
|
-
@dirty = false
|
15
|
-
@internal_values =
|
16
|
-
if klass = MicrosoftGraph::ClassBuilder.get_namespaced_class(type.member_type.name)
|
17
|
-
initial_values.map { |v| klass.new(attributes: v) }
|
18
|
-
else
|
19
|
-
initial_values
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def each
|
24
|
-
values.each do |value|
|
25
|
-
yield value
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def <<(value)
|
30
|
-
unless @type.valid_value?(value)
|
31
|
-
raise MicrosoftGraph::TypeError.new(
|
32
|
-
"Value \"#{value}\" does not match type #{@type.member_type.name}"
|
33
|
-
)
|
34
|
-
end
|
35
|
-
@dirty = true
|
36
|
-
@internal_values << value
|
37
|
-
self
|
38
|
-
end
|
39
|
-
|
40
|
-
def []=(index, value)
|
41
|
-
raise MicrosoftGraph::TypeError unless @type.valid_value?(value)
|
42
|
-
@dirty = true
|
43
|
-
values[index] = value
|
44
|
-
end
|
45
|
-
|
46
|
-
def dirty?
|
47
|
-
@dirty || @internal_values.any? { |value|
|
48
|
-
value.respond_to?(:dirty?) && value.dirty?
|
49
|
-
}
|
50
|
-
end
|
51
|
-
|
52
|
-
def mark_clean
|
53
|
-
@dirty = false
|
54
|
-
@internal_values.each { |value|
|
55
|
-
value.respond_to?(:mark_clean) && value.mark_clean
|
56
|
-
}
|
57
|
-
end
|
58
|
-
|
59
|
-
def as_json(options = {})
|
60
|
-
values.map do |value|
|
61
|
-
if value.respond_to? :as_json
|
62
|
-
value.as_json(options)
|
63
|
-
else
|
64
|
-
value
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def new(attributes = {})
|
70
|
-
klass = MicrosoftGraph::ClassBuilder.get_namespaced_class(@type.member_type.name)
|
71
|
-
if klass
|
72
|
-
new_instance = klass.new(graph: graph, attributes: attributes)
|
73
|
-
self << new_instance
|
74
|
-
new_instance
|
75
|
-
else
|
76
|
-
raise NoMethodError.new("undefined method `new' for #{as_json}:#{self.class}")
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def parental_chain
|
81
|
-
if parent && parent.respond_to?(:parental_chain)
|
82
|
-
parent.parental_chain.concat([parent])
|
83
|
-
else
|
84
|
-
[parent]
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
private
|
89
|
-
|
90
|
-
def values
|
91
|
-
@internal_values
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
end
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
class MicrosoftGraph
|
4
|
+
class Collection
|
5
|
+
include Enumerable
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
attr_accessor :graph
|
9
|
+
|
10
|
+
def_delegators :values, :size, :length, :include?, :empty?, :[]
|
11
|
+
|
12
|
+
def initialize(type, initial_values = [])
|
13
|
+
@type = type
|
14
|
+
@dirty = false
|
15
|
+
@internal_values =
|
16
|
+
if klass = MicrosoftGraph::ClassBuilder.get_namespaced_class(type.member_type.name)
|
17
|
+
initial_values.map { |v| klass.new(attributes: v) }
|
18
|
+
else
|
19
|
+
initial_values
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def each
|
24
|
+
values.each do |value|
|
25
|
+
yield value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def <<(value)
|
30
|
+
unless @type.valid_value?(value)
|
31
|
+
raise MicrosoftGraph::TypeError.new(
|
32
|
+
"Value \"#{value}\" does not match type #{@type.member_type.name}"
|
33
|
+
)
|
34
|
+
end
|
35
|
+
@dirty = true
|
36
|
+
@internal_values << value
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def []=(index, value)
|
41
|
+
raise MicrosoftGraph::TypeError unless @type.valid_value?(value)
|
42
|
+
@dirty = true
|
43
|
+
values[index] = value
|
44
|
+
end
|
45
|
+
|
46
|
+
def dirty?
|
47
|
+
@dirty || @internal_values.any? { |value|
|
48
|
+
value.respond_to?(:dirty?) && value.dirty?
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def mark_clean
|
53
|
+
@dirty = false
|
54
|
+
@internal_values.each { |value|
|
55
|
+
value.respond_to?(:mark_clean) && value.mark_clean
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def as_json(options = {})
|
60
|
+
values.map do |value|
|
61
|
+
if value.respond_to? :as_json
|
62
|
+
value.as_json(options)
|
63
|
+
else
|
64
|
+
value
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def new(attributes = {})
|
70
|
+
klass = MicrosoftGraph::ClassBuilder.get_namespaced_class(@type.member_type.name)
|
71
|
+
if klass
|
72
|
+
new_instance = klass.new(graph: graph, attributes: attributes)
|
73
|
+
self << new_instance
|
74
|
+
new_instance
|
75
|
+
else
|
76
|
+
raise NoMethodError.new("undefined method `new' for #{as_json}:#{self.class}")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def parental_chain
|
81
|
+
if parent && parent.respond_to?(:parental_chain)
|
82
|
+
parent.parental_chain.concat([parent])
|
83
|
+
else
|
84
|
+
[parent]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def values
|
91
|
+
@internal_values
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|