occi-core 4.3.6 → 5.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (359) hide show
  1. checksums.yaml +4 -4
  2. data/.fasterer.yml +3 -0
  3. data/.gitignore +9 -16
  4. data/.rspec +1 -1
  5. data/.rubocop.yml +69 -0
  6. data/.travis.yml +27 -0
  7. data/AUTHORS +8 -6
  8. data/CHANGELOG.md +0 -0
  9. data/Gemfile +1 -1
  10. data/LICENSE +1 -1
  11. data/README.md +25 -170
  12. data/Rakefile +25 -17
  13. data/examples/initialize_model.rb +10 -0
  14. data/examples/parse_action_instance_json.rb +15 -0
  15. data/examples/parse_action_instance_text.rb +15 -0
  16. data/examples/parse_categories_json.rb +15 -0
  17. data/examples/parse_categories_text.rb +15 -0
  18. data/examples/parse_instance_json.rb +15 -0
  19. data/examples/parse_instance_text.rb +15 -0
  20. data/examples/parse_model_json.rb +9 -0
  21. data/examples/parse_model_text.rb +9 -0
  22. data/examples/render_action_instance_json.rb +17 -0
  23. data/examples/render_action_instance_text.rb +17 -0
  24. data/examples/render_instance_json.rb +20 -0
  25. data/examples/render_instance_text.rb +20 -0
  26. data/examples/render_model_json.rb +12 -0
  27. data/examples/render_model_text.rb +12 -0
  28. data/examples/rendering/action_instance.json +6 -0
  29. data/examples/rendering/action_instance.txt +2 -0
  30. data/examples/rendering/categories.json +78 -0
  31. data/examples/rendering/categories.txt +4 -0
  32. data/examples/rendering/instance.json +70 -0
  33. data/examples/rendering/instance.txt +12 -0
  34. data/examples/rendering/model.alt.json +1716 -0
  35. data/examples/rendering/model.json +785 -0
  36. data/examples/rendering/model.txt +68 -0
  37. data/lib/occi/core/action.rb +12 -26
  38. data/lib/occi/core/action_instance.rb +109 -65
  39. data/lib/occi/core/attribute.rb +136 -0
  40. data/lib/occi/core/attribute_definition.rb +269 -0
  41. data/lib/occi/core/category.rb +110 -83
  42. data/lib/occi/core/collection.rb +255 -0
  43. data/lib/occi/core/constants.rb +14 -0
  44. data/lib/occi/core/entity.rb +301 -195
  45. data/lib/occi/core/errors/.gitkeep +0 -0
  46. data/lib/occi/core/errors/attribute_definition_error.rb +11 -0
  47. data/lib/occi/core/errors/attribute_validation_error.rb +13 -0
  48. data/lib/occi/core/errors/category_validation_error.rb +13 -0
  49. data/lib/occi/core/errors/collection_lookup_error.rb +11 -0
  50. data/lib/occi/core/errors/instance_validation_error.rb +13 -0
  51. data/lib/occi/core/errors/mandatory_argument_error.rb +11 -0
  52. data/lib/occi/core/errors/model_lookup_error.rb +11 -0
  53. data/lib/occi/core/errors/parser_error.rb +11 -0
  54. data/lib/occi/core/errors/parsing_error.rb +11 -0
  55. data/lib/occi/core/errors/renderer_error.rb +11 -0
  56. data/lib/occi/core/errors/rendering_error.rb +11 -0
  57. data/lib/occi/core/errors/validation_error.rb +11 -0
  58. data/lib/occi/core/errors.rb +9 -0
  59. data/lib/occi/core/helpers/.gitkeep +0 -0
  60. data/lib/occi/core/helpers/argument_validator.rb +27 -0
  61. data/lib/occi/core/helpers/attributes_accessor.rb +22 -0
  62. data/lib/occi/core/helpers/error_handler.rb +29 -0
  63. data/lib/occi/core/helpers/hash_dereferencer.rb +149 -0
  64. data/lib/occi/core/helpers/identifier_validator.rb +135 -0
  65. data/lib/occi/core/helpers/instance_attribute_resetter.rb +131 -0
  66. data/lib/occi/core/helpers/instance_attributes_accessor.rb +30 -0
  67. data/lib/occi/core/helpers/locatable.rb +40 -0
  68. data/lib/occi/core/helpers/parser_dereferencer.rb +96 -0
  69. data/lib/occi/core/helpers/raw_json_parser.rb +18 -0
  70. data/lib/occi/core/helpers/renderable.rb +93 -0
  71. data/lib/occi/core/helpers/yaml_summoner.rb +44 -0
  72. data/lib/occi/core/helpers.rb +13 -0
  73. data/lib/occi/core/instance_builder.rb +162 -0
  74. data/lib/occi/core/kind.rb +100 -132
  75. data/lib/occi/core/link.rb +47 -72
  76. data/lib/occi/core/mixin.rb +76 -61
  77. data/lib/occi/core/model.rb +341 -0
  78. data/lib/occi/core/parsers/.gitkeep +0 -0
  79. data/lib/occi/core/parsers/base_parser.rb +168 -0
  80. data/lib/occi/core/parsers/json/.gitkeep +0 -0
  81. data/lib/occi/core/parsers/json/action_instance.rb +36 -0
  82. data/lib/occi/core/parsers/json/category.rb +113 -0
  83. data/lib/occi/core/parsers/json/entity.rb +156 -0
  84. data/lib/occi/core/parsers/json/validator/.gitkeep +0 -0
  85. data/lib/occi/core/parsers/json/validator/action-instance.json +3 -0
  86. data/lib/occi/core/parsers/json/validator/entity-collection.json +3 -0
  87. data/lib/occi/core/parsers/json/validator/link-collection.json +3 -0
  88. data/lib/occi/core/parsers/json/validator/link.json +3 -0
  89. data/lib/occi/core/parsers/json/validator/locations.json +3 -0
  90. data/lib/occi/core/parsers/json/validator/mixin-collection.json +3 -0
  91. data/lib/occi/core/parsers/json/validator/model.json +3 -0
  92. data/lib/occi/core/parsers/json/validator/occi-schema.json +277 -0
  93. data/lib/occi/core/parsers/json/validator/resource-collection.json +3 -0
  94. data/lib/occi/core/parsers/json/validator/resource.json +3 -0
  95. data/lib/occi/core/parsers/json/validator.rb +87 -0
  96. data/lib/occi/core/parsers/json_parser.rb +128 -0
  97. data/lib/occi/core/parsers/text/.gitkeep +0 -0
  98. data/lib/occi/core/parsers/text/category.rb +183 -0
  99. data/lib/occi/core/parsers/text/constants.rb +89 -0
  100. data/lib/occi/core/parsers/text/entity.rb +257 -0
  101. data/lib/occi/core/parsers/text/location.rb +48 -0
  102. data/lib/occi/core/parsers/text_parser.rb +257 -0
  103. data/lib/occi/core/parsers.rb +18 -0
  104. data/lib/occi/core/renderer_factory.rb +213 -0
  105. data/lib/occi/core/renderers/.gitkeep +0 -0
  106. data/lib/occi/core/renderers/base_renderer.rb +81 -0
  107. data/lib/occi/core/renderers/json/.gitkeep +0 -0
  108. data/lib/occi/core/renderers/json/action_instance.rb +24 -0
  109. data/lib/occi/core/renderers/json/attributes.rb +50 -0
  110. data/lib/occi/core/renderers/json/base.rb +46 -0
  111. data/lib/occi/core/renderers/json/category.rb +85 -0
  112. data/lib/occi/core/renderers/json/collection.rb +52 -0
  113. data/lib/occi/core/renderers/json/instance.rb +39 -0
  114. data/lib/occi/core/renderers/json/link.rb +48 -0
  115. data/lib/occi/core/renderers/json/model.rb +26 -0
  116. data/lib/occi/core/renderers/json/resource.rb +27 -0
  117. data/lib/occi/core/renderers/json_renderer.rb +72 -0
  118. data/lib/occi/core/renderers/text/.gitkeep +0 -0
  119. data/lib/occi/core/renderers/text/action_instance.rb +36 -0
  120. data/lib/occi/core/renderers/text/attributes.rb +87 -0
  121. data/lib/occi/core/renderers/text/base.rb +82 -0
  122. data/lib/occi/core/renderers/text/category.rb +183 -0
  123. data/lib/occi/core/renderers/text/collection.rb +65 -0
  124. data/lib/occi/core/renderers/text/instance.rb +44 -0
  125. data/lib/occi/core/renderers/text/link.rb +40 -0
  126. data/lib/occi/core/renderers/text/model.rb +41 -0
  127. data/lib/occi/core/renderers/text/resource.rb +109 -0
  128. data/lib/occi/core/renderers/text_renderer.rb +72 -0
  129. data/lib/occi/core/renderers.rb +20 -0
  130. data/lib/occi/core/resource.rb +93 -57
  131. data/lib/occi/core/utils/.gitkeep +0 -0
  132. data/lib/occi/core/version.rb +17 -0
  133. data/lib/occi/core/warehouse/actions/.gitkeep +0 -0
  134. data/lib/occi/core/warehouse/actions/attributes/.gitkeep +0 -0
  135. data/lib/occi/core/warehouse/kinds/.gitkeep +0 -0
  136. data/lib/occi/core/warehouse/kinds/attributes/.gitkeep +0 -0
  137. data/lib/occi/core/warehouse/kinds/attributes/occi.core.id.yml +7 -0
  138. data/lib/occi/core/warehouse/kinds/attributes/occi.core.source.yml +7 -0
  139. data/lib/occi/core/warehouse/kinds/attributes/occi.core.summary.yml +7 -0
  140. data/lib/occi/core/warehouse/kinds/attributes/occi.core.target.yml +7 -0
  141. data/lib/occi/core/warehouse/kinds/attributes/occi.core.title.yml +7 -0
  142. data/lib/occi/core/warehouse/kinds/entity.yml +10 -0
  143. data/lib/occi/core/warehouse/kinds/link.yml +10 -0
  144. data/lib/occi/core/warehouse/kinds/resource.yml +9 -0
  145. data/lib/occi/core/warehouse/mixins/.gitkeep +0 -0
  146. data/lib/occi/core/warehouse/mixins/attributes/.gitkeep +0 -0
  147. data/lib/occi/core/warehouse.rb +115 -0
  148. data/lib/occi/core.rb +59 -23
  149. data/lib/occi/infrastructure/compute.rb +5 -122
  150. data/lib/occi/infrastructure/constants.rb +25 -0
  151. data/lib/occi/infrastructure/instance_builder.rb +24 -0
  152. data/lib/occi/infrastructure/mixins/.gitkeep +0 -0
  153. data/lib/occi/infrastructure/mixins/os_tpl.rb +19 -0
  154. data/lib/occi/infrastructure/mixins/resource_tpl.rb +19 -0
  155. data/lib/occi/infrastructure/mixins.rb +12 -0
  156. data/lib/occi/infrastructure/model.rb +27 -0
  157. data/lib/occi/infrastructure/network.rb +5 -104
  158. data/lib/occi/infrastructure/networkinterface.rb +5 -100
  159. data/lib/occi/infrastructure/storage.rb +5 -59
  160. data/lib/occi/infrastructure/storagelink.rb +5 -54
  161. data/lib/occi/infrastructure/version.rb +5 -0
  162. data/lib/occi/infrastructure/warehouse/actions/.gitkeep +0 -0
  163. data/lib/occi/infrastructure/warehouse/actions/attributes/.gitkeep +0 -0
  164. data/lib/occi/infrastructure/warehouse/actions/compute_restart.yml +12 -0
  165. data/lib/occi/infrastructure/warehouse/actions/compute_save.yml +19 -0
  166. data/lib/occi/infrastructure/warehouse/actions/compute_start.yml +4 -0
  167. data/lib/occi/infrastructure/warehouse/actions/compute_stop.yml +12 -0
  168. data/lib/occi/infrastructure/warehouse/actions/compute_suspend.yml +12 -0
  169. data/lib/occi/infrastructure/warehouse/actions/network_down.yml +4 -0
  170. data/lib/occi/infrastructure/warehouse/actions/network_up.yml +4 -0
  171. data/lib/occi/infrastructure/warehouse/actions/networkinterface_down.yml +4 -0
  172. data/lib/occi/infrastructure/warehouse/actions/networkinterface_up.yml +4 -0
  173. data/lib/occi/infrastructure/warehouse/actions/storage_backup.yml +4 -0
  174. data/lib/occi/infrastructure/warehouse/actions/storage_offline.yml +4 -0
  175. data/lib/occi/infrastructure/warehouse/actions/storage_online.yml +4 -0
  176. data/lib/occi/infrastructure/warehouse/actions/storage_resize.yml +12 -0
  177. data/lib/occi/infrastructure/warehouse/actions/storage_snapshot.yml +4 -0
  178. data/lib/occi/infrastructure/warehouse/actions/storagelink_offline.yml +4 -0
  179. data/lib/occi/infrastructure/warehouse/actions/storagelink_online.yml +4 -0
  180. data/lib/occi/infrastructure/warehouse/kinds/.gitkeep +0 -0
  181. data/lib/occi/infrastructure/warehouse/kinds/attributes/.gitkeep +0 -0
  182. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.architecture.yml +7 -0
  183. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.cores.yml +7 -0
  184. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.hostname.yml +7 -0
  185. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.memory.yml +7 -0
  186. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.speed.yml +7 -0
  187. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.state.yml +7 -0
  188. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.network.label.yml +7 -0
  189. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.network.state.yml +7 -0
  190. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.network.vlan.yml +7 -0
  191. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.networkinterface.interface.yml +7 -0
  192. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.networkinterface.mac.yml +7 -0
  193. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.networkinterface.state.yml +7 -0
  194. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storage.size.yml +7 -0
  195. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storage.state.yml +7 -0
  196. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storagelink.deviceid.yml +7 -0
  197. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storagelink.mountpoint.yml +7 -0
  198. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storagelink.state.yml +7 -0
  199. data/lib/occi/infrastructure/warehouse/kinds/compute.yml +19 -0
  200. data/lib/occi/infrastructure/warehouse/kinds/network.yml +13 -0
  201. data/lib/occi/infrastructure/warehouse/kinds/networkinterface.yml +13 -0
  202. data/lib/occi/infrastructure/warehouse/kinds/storage.yml +15 -0
  203. data/lib/occi/infrastructure/warehouse/kinds/storagelink.yml +13 -0
  204. data/lib/occi/infrastructure/warehouse/mixins/.gitkeep +0 -0
  205. data/lib/occi/infrastructure/warehouse/mixins/attributes/.gitkeep +0 -0
  206. data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.network.address.yml +7 -0
  207. data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.network.allocation.yml +7 -0
  208. data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.network.gateway.yml +7 -0
  209. data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.networkinterface.address.yml +7 -0
  210. data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.networkinterface.allocation.yml +7 -0
  211. data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.networkinterface.gateway.yml +7 -0
  212. data/lib/occi/infrastructure/warehouse/mixins/ipnetwork.yml +11 -0
  213. data/lib/occi/infrastructure/warehouse/mixins/ipnetworkinterface.yml +11 -0
  214. data/lib/occi/infrastructure/warehouse.rb +20 -0
  215. data/lib/occi/infrastructure-ext.rb +35 -0
  216. data/lib/occi/infrastructure.rb +34 -19
  217. data/lib/occi/infrastructure_ext/constants.rb +20 -0
  218. data/lib/occi/infrastructure_ext/instance_builder.rb +22 -0
  219. data/lib/occi/infrastructure_ext/ipreservation.rb +9 -0
  220. data/lib/occi/infrastructure_ext/mixins/.gitkeep +0 -0
  221. data/lib/occi/infrastructure_ext/mixins/availability_zone.rb +19 -0
  222. data/lib/occi/infrastructure_ext/mixins.rb +12 -0
  223. data/lib/occi/infrastructure_ext/model.rb +26 -0
  224. data/lib/occi/infrastructure_ext/securitygroup.rb +9 -0
  225. data/lib/occi/infrastructure_ext/securitygrouplink.rb +9 -0
  226. data/lib/occi/infrastructure_ext/version.rb +5 -0
  227. data/lib/occi/infrastructure_ext/warehouse/actions/.gitkeep +0 -0
  228. data/lib/occi/infrastructure_ext/warehouse/actions/attributes/.gitkeep +0 -0
  229. data/lib/occi/infrastructure_ext/warehouse/actions/ipreservation_down.yml +4 -0
  230. data/lib/occi/infrastructure_ext/warehouse/actions/ipreservation_up.yml +4 -0
  231. data/lib/occi/infrastructure_ext/warehouse/kinds/.gitkeep +0 -0
  232. data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/.gitkeep +0 -0
  233. data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.ipreservation.address.yml +7 -0
  234. data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.ipreservation.state.yml +7 -0
  235. data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.ipreservation.used.yml +7 -0
  236. data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.securitygroup.rules.yml +7 -0
  237. data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.securitygroup.state.yml +7 -0
  238. data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.securitygrouplink.state.yml +7 -0
  239. data/lib/occi/infrastructure_ext/warehouse/kinds/ipreservation.yml +13 -0
  240. data/lib/occi/infrastructure_ext/warehouse/kinds/securitygroup.yml +9 -0
  241. data/lib/occi/infrastructure_ext/warehouse/kinds/securitygrouplink.yml +8 -0
  242. data/lib/occi/infrastructure_ext/warehouse/mixins/.gitkeep +0 -0
  243. data/lib/occi/infrastructure_ext/warehouse/mixins/attributes/.gitkeep +0 -0
  244. data/lib/occi/infrastructure_ext/warehouse.rb +20 -0
  245. data/lib/occi/monkey_island/boolean.rb +6 -0
  246. data/lib/occi/monkey_island/hash.rb +4 -0
  247. data/occi-core.gemspec +26 -26
  248. metadata +312 -243
  249. data/.yardopts +0 -1
  250. data/config/occi.yml +0 -4
  251. data/lib/occi/collection.rb +0 -265
  252. data/lib/occi/core/actions.rb +0 -21
  253. data/lib/occi/core/attributes.rb +0 -411
  254. data/lib/occi/core/categories.rb +0 -64
  255. data/lib/occi/core/dependencies.rb +0 -7
  256. data/lib/occi/core/entities.rb +0 -48
  257. data/lib/occi/core/kinds.rb +0 -22
  258. data/lib/occi/core/links.rb +0 -37
  259. data/lib/occi/core/mixins.rb +0 -37
  260. data/lib/occi/core/properties.rb +0 -108
  261. data/lib/occi/core/resources.rb +0 -14
  262. data/lib/occi/errors/attribute_definitions_converted_error.rb +0 -5
  263. data/lib/occi/errors/attribute_missing_error.rb +0 -5
  264. data/lib/occi/errors/attribute_name_invalid_error.rb +0 -5
  265. data/lib/occi/errors/attribute_not_defined_error.rb +0 -5
  266. data/lib/occi/errors/attribute_property_type_error.rb +0 -5
  267. data/lib/occi/errors/attribute_type_error.rb +0 -5
  268. data/lib/occi/errors/category_not_defined_error.rb +0 -5
  269. data/lib/occi/errors/kind_not_defined_error.rb +0 -5
  270. data/lib/occi/errors/parser_input_error.rb +0 -5
  271. data/lib/occi/errors/parser_type_error.rb +0 -5
  272. data/lib/occi/errors.rb +0 -1
  273. data/lib/occi/extensions/hashie.rb +0 -25
  274. data/lib/occi/helpers/comparators/action_instance.rb +0 -22
  275. data/lib/occi/helpers/comparators/attributes.rb +0 -22
  276. data/lib/occi/helpers/comparators/categories.rb +0 -22
  277. data/lib/occi/helpers/comparators/category.rb +0 -22
  278. data/lib/occi/helpers/comparators/collection.rb +0 -40
  279. data/lib/occi/helpers/comparators/entities.rb +0 -22
  280. data/lib/occi/helpers/comparators/entity.rb +0 -22
  281. data/lib/occi/helpers/comparators/properties.rb +0 -26
  282. data/lib/occi/helpers/comparators.rb +0 -1
  283. data/lib/occi/helpers/inspect.rb +0 -12
  284. data/lib/occi/infrastructure/network/ipnetwork.rb +0 -28
  285. data/lib/occi/infrastructure/networkinterface/ipnetworkinterface.rb +0 -28
  286. data/lib/occi/infrastructure/os_tpl.rb +0 -20
  287. data/lib/occi/infrastructure/resource_tpl.rb +0 -20
  288. data/lib/occi/log.rb +0 -71
  289. data/lib/occi/model.rb +0 -87
  290. data/lib/occi/parser/json.rb +0 -38
  291. data/lib/occi/parser/text/constants.rb +0 -89
  292. data/lib/occi/parser/text.rb +0 -280
  293. data/lib/occi/parser.rb +0 -144
  294. data/lib/occi/settings.rb +0 -10
  295. data/lib/occi/version.rb +0 -3
  296. data/lib/occi-core.rb +0 -53
  297. data/spec/helpers/to_plain.rb +0 -39
  298. data/spec/helpers/yaml_hash.rb +0 -32
  299. data/spec/occi/collection_samples/collection1.json +0 -1
  300. data/spec/occi/collection_samples/directory2/collection2.json +0 -1
  301. data/spec/occi/collection_spec.rb +0 -1003
  302. data/spec/occi/core/action_instance_spec.rb +0 -317
  303. data/spec/occi/core/action_spec.rb +0 -71
  304. data/spec/occi/core/attributes_spec.rb +0 -665
  305. data/spec/occi/core/categories_spec.rb +0 -28
  306. data/spec/occi/core/category_spec.rb +0 -216
  307. data/spec/occi/core/entities_spec.rb +0 -160
  308. data/spec/occi/core/entity_spec.rb +0 -374
  309. data/spec/occi/core/kind_spec.rb +0 -182
  310. data/spec/occi/core/link_spec.rb +0 -52
  311. data/spec/occi/core/links_spec.rb +0 -132
  312. data/spec/occi/core/mixin_spec.rb +0 -38
  313. data/spec/occi/core/mixins_spec.rb +0 -107
  314. data/spec/occi/core/properties_spec.rb +0 -171
  315. data/spec/occi/core/resource_spec.rb +0 -42
  316. data/spec/occi/core_spec.rb +0 -12
  317. data/spec/occi/infrastructure/compute_spec.rb +0 -229
  318. data/spec/occi/infrastructure/network_spec.rb +0 -96
  319. data/spec/occi/infrastructure/networkinterface_spec.rb +0 -96
  320. data/spec/occi/infrastructure/storage_spec.rb +0 -33
  321. data/spec/occi/infrastructure/storagelink_spec.rb +0 -45
  322. data/spec/occi/log_spec.rb +0 -117
  323. data/spec/occi/model_spec.rb +0 -256
  324. data/spec/occi/parser/json_samples/test.json +0 -49
  325. data/spec/occi/parser/text_samples/occi_categories.body_plain.expected +0 -2
  326. data/spec/occi/parser/text_samples/occi_categories.expected +0 -2
  327. data/spec/occi/parser/text_samples/occi_categories.parse_headers.expected +0 -2
  328. data/spec/occi/parser/text_samples/occi_categories.text +0 -2
  329. data/spec/occi/parser/text_samples/occi_compute_rocci_server.expected +0 -11
  330. data/spec/occi/parser/text_samples/occi_compute_rocci_server.text +0 -10
  331. data/spec/occi/parser/text_samples/occi_link_resource_instance.body_plain.expected +0 -7
  332. data/spec/occi/parser/text_samples/occi_link_resource_instance.expected +0 -7
  333. data/spec/occi/parser/text_samples/occi_link_resource_instance.parse.expected +0 -7
  334. data/spec/occi/parser/text_samples/occi_link_resource_instance.text +0 -7
  335. data/spec/occi/parser/text_samples/occi_link_simple.expected +0 -7
  336. data/spec/occi/parser/text_samples/occi_link_simple.text +0 -1
  337. data/spec/occi/parser/text_samples/occi_link_w_attributes.expected +0 -7
  338. data/spec/occi/parser/text_samples/occi_link_w_attributes.text +0 -7
  339. data/spec/occi/parser/text_samples/occi_link_w_category.expected +0 -7
  340. data/spec/occi/parser/text_samples/occi_link_w_category.text +0 -3
  341. data/spec/occi/parser/text_samples/occi_model_categories.expected +0 -3
  342. data/spec/occi/parser/text_samples/occi_model_rocci_server.text +0 -51
  343. data/spec/occi/parser/text_samples/occi_network_rocci_server.body_plain.expected +0 -11
  344. data/spec/occi/parser/text_samples/occi_network_rocci_server.expected +0 -11
  345. data/spec/occi/parser/text_samples/occi_network_rocci_server.resource.header.expected +0 -9
  346. data/spec/occi/parser/text_samples/occi_network_rocci_server.resource.rack.expected +0 -9
  347. data/spec/occi/parser/text_samples/occi_network_rocci_server.text +0 -11
  348. data/spec/occi/parser/text_samples/occi_resource_custom_class_w_attributes.parse.expected +0 -15
  349. data/spec/occi/parser/text_samples/occi_resource_custom_class_w_attributes.text +0 -15
  350. data/spec/occi/parser/text_samples/occi_resource_w_attributes.text +0 -11
  351. data/spec/occi/parser/text_samples/occi_resource_w_inline_links.expected +0 -1
  352. data/spec/occi/parser/text_samples/occi_resource_w_inline_links.text +0 -16
  353. data/spec/occi/parser/text_samples/occi_resource_w_inline_links_only.text +0 -13
  354. data/spec/occi/parser/text_samples/occi_storage_rocci_server.expected +0 -9
  355. data/spec/occi/parser/text_samples/occi_storage_rocci_server.text +0 -9
  356. data/spec/occi/parser/text_spec.rb +0 -320
  357. data/spec/occi/parser_spec.rb +0 -259
  358. data/spec/occi-core_spec.rb +0 -31
  359. data/spec/spec_helper.rb +0 -18
data/.yardopts DELETED
@@ -1 +0,0 @@
1
- --title "Documentation of the OCCI gem" --markup markdown --private
data/config/occi.yml DELETED
@@ -1,4 +0,0 @@
1
- # config/occi.yml
2
- core: &core
3
- compatibility: true
4
- verify_attribute_pattern: false
@@ -1,265 +0,0 @@
1
- module Occi
2
- class Collection
3
-
4
- include Occi::Helpers::Inspect
5
- include Occi::Helpers::Comparators::Collection
6
-
7
- attr_accessor :kinds, :mixins, :actions, :resources, :links, :action, :model
8
-
9
- # Initialize a new OCCI Collection by initializing all supplied OCCI objects
10
- #
11
- # @param [Hash] collection including one or more of the keys kinds, mixins, actions, resources, links
12
- def initialize(collection={}, model = Occi::Model.new)
13
- collection = Hashie::Mash.new(collection) unless collection.kind_of? Occi::Collection
14
-
15
- @kinds = Occi::Core::Kinds.new
16
- @mixins = Occi::Core::Mixins.new
17
- @actions = Occi::Core::Actions.new
18
- @resources = Occi::Core::Resources.new
19
- @links = Occi::Core::Links.new
20
-
21
- @kinds.merge collection.kinds.to_a.collect { |kind| Occi::Core::Kind.new(kind.scheme, kind.term, kind.title, kind.attributes, kind.related, kind.actions, kind.location) }
22
- @mixins.merge collection.mixins.to_a.collect { |mixin| Occi::Core::Mixin.new(mixin.scheme, mixin.term, mixin.title, mixin.attributes, mixin.depends, mixin.actions, mixin.location, mixin.applies) }
23
- @actions.merge collection.actions.to_a.collect { |action| Occi::Core::Action.new(action.scheme, action.term, action.title, action.attributes) }
24
- @resources.merge collection.resources.to_a.collect { |resource| Occi::Core::Resource.new(resource.kind, resource.mixins, resource.attributes, resource.actions, resource.links, resource.location) }
25
- @links.merge collection.links.to_a.collect { |link| Occi::Core::Link.new(link.kind, link.mixins, link.attributes, link.actions, link.rel, link.target, link.source, link.location) }
26
- @action = Occi::Core::ActionInstance.new(collection.action.action, collection.action.attributes) if collection.action
27
-
28
- self.model = model if model
29
- end
30
-
31
- def <<(object)
32
- self.kinds << object if object.kind_of? Occi::Core::Kind
33
- self.mixins << object if object.kind_of? Occi::Core::Mixin
34
- self.actions << object if object.kind_of? Occi::Core::Action
35
- self.resources << object if object.kind_of? Occi::Core::Resource
36
- self.links << object if object.kind_of? Occi::Core::Link
37
-
38
- self.action = object if object.kind_of? Occi::Core::ActionInstance
39
-
40
- self
41
- end
42
-
43
- # @return [Occi::Core::Categories] categories combined list of all kinds, mixins and actions
44
- def categories
45
- Occi::Core::Categories.new(@kinds + @mixins + @actions)
46
- end
47
-
48
- # @return [Occi::Core::Entities] entities combined list of all resources and links
49
- def entities
50
- Occi::Core::Entities.new(@resources + @links)
51
- end
52
-
53
- # @param [Occi::Core::Model] model
54
- # @return [Occi::Core::Model]
55
- def model=(model)
56
- @model = model
57
-
58
- @kinds.model = model
59
- @mixins.model = model
60
- @actions.model = model
61
- @resources.model = model
62
- @links.model = model
63
-
64
- @action.model = model if @action
65
- end
66
-
67
- # @param incl_categories [Boolean] check every category against the model
68
- # @param set_default_attrs [Boolean] set default attribute values for all entities
69
- # @return [Boolean] result
70
- def check(incl_categories = false, set_default_attrs = false)
71
- @resources.check(set_default_attrs)
72
- @links.check(set_default_attrs)
73
- @action.check(set_default_attrs) if @action
74
-
75
- if incl_categories
76
- @kinds.check
77
- @mixins.check
78
- @actions.check
79
- end
80
-
81
- true
82
- end
83
-
84
- # @param [Occi::Collection] other_collection
85
- # @return [Occi::Collection]
86
- def merge!(other_collection)
87
- self.kinds.merge other_collection.kinds.select { |kind| get_by_id(kind.type_identifier).nil? }
88
- self.mixins.merge other_collection.mixins.select { |mixin| get_by_id(mixin.type_identifier).nil? }
89
- self.actions.merge other_collection.actions.select { |action| get_by_id(action.type_identifier).nil? }
90
- self.resources.merge other_collection.resources.select { |resource| get_by_id(resource.id).nil? }
91
- self.links.merge other_collection.links.select { |link| get_by_id(link.id).nil? }
92
- self.action = other_collection.action if other_collection.action
93
- end
94
-
95
- # @param [Occi::Collection] other_collection
96
- # @param [Occi::Collection] collection
97
- # @return [Occi::Collection]
98
- def merge(other_collection, first=self)
99
- collection = Occi::Collection.new
100
-
101
- collection.merge!(first)
102
- collection.merge!(other_collection)
103
-
104
- collection
105
- end
106
-
107
- # @param [Occi::Collection] other_collection
108
- # @return [Occi::Collection]
109
- def intersect!(other_collection)
110
- intersect other_collection, self
111
- end
112
-
113
- # @param [Occi::Collection] other_collection
114
- # @param [Occi::Collection] collection
115
- # @return [Occi::Collection]
116
- def intersect(other_collection, collection=self.clone)
117
- collection.kinds.replace other_collection.kinds.select { |kind| get_by_id(kind.type_identifier) }
118
- collection.mixins.replace other_collection.mixins.select { |mixin| get_by_id(mixin.type_identifier) }
119
- collection.actions.replace other_collection.actions.select { |action| get_by_id(action.type_identifier) }
120
- collection.resources.replace other_collection.resources.select { |resource| get_by_id(resource.id) }
121
- collection.links.replace other_collection.links.select { |link| get_by_id(link.id) }
122
-
123
- if collection.action == other_collection.action
124
- collection.action = other_collection.action
125
- else
126
- collection.action = nil
127
- end
128
-
129
- collection
130
- end
131
-
132
- # Returns the category corresponding to a given id
133
- #
134
- # @param id [String] identifier
135
- # @param cats_only [Boolean] look only for categories
136
- # @return [Occi::Core::Category]
137
- def get_by_id(id, cats_only = false)
138
- raise "Cannot do a look-up with a blank id!" if id.blank?
139
- object = self.categories.select { |category| category.type_identifier == id }
140
- object = self.entities.select { |entity| entity.id == id } if !cats_only && object.empty?
141
- object.first
142
- end
143
-
144
- # Returns the category corresponding to a given location
145
- #
146
- # @param [String] location
147
- # @return [Occi::Core::Category]
148
- def get_by_location(location)
149
- raise "Cannot do a look-up with a blank location!" if location.blank?
150
- self.categories.select { |category| category.location == instance2cat(location) }.first
151
- end
152
-
153
- # @return [true,false] true if collection is empty, false otherwise
154
- def empty?
155
- @kinds.empty? && @mixins.empty? && @actions.empty? && @resources.empty? && @links.empty? && @action.nil?
156
- end
157
-
158
- # Returns a collection with all categories related to the specified category
159
- #
160
- # @param [Occi::Core::Category, String] category
161
- # @return [Occi::Core::Collection]
162
- def get_related_to(category)
163
- raise "Cannot do a look-up with a blank category!" if category.blank?
164
- collection = self.class.new
165
- collection.kinds = @kinds.get_related_to(category)
166
- collection.mixins = @mixins.get_related_to(category)
167
- collection
168
- end
169
-
170
- # @return [Hashie::Mash] json representation
171
- def as_json(options = {})
172
- return @action.as_json if standalone_action_instance?
173
-
174
- collection = Hashie::Mash.new
175
- collection.kinds = @kinds.collect { |kind| kind.as_json } if @kinds.any?
176
- collection.mixins = @mixins.collect { |mixin| mixin.as_json } if @mixins.any?
177
- collection.actions = @actions.collect { |action_category| action_category.as_json } if @actions.any?
178
- collection.resources = @resources.collect { |resource| resource.as_json } if @resources.any?
179
-
180
- # if there is only one resource and the links inside the resource have no location,
181
- # then these links must be rendered as separate links inside the collection
182
- if collection.resources && collection.resources.size == 1
183
- if collection.resources.first.links.blank? && @links.empty?
184
- lnks = @resources.first.links
185
- else
186
- lnks = @links
187
- end
188
- else
189
- lnks = @links
190
- end
191
- collection.links = lnks.collect { |link| link.as_json } if lnks.to_a.any?
192
-
193
- collection
194
- end
195
-
196
- # @return [String] text representation
197
- def to_text
198
- text = ""
199
-
200
- if standalone_links?
201
- raise "Only one standalone link allowed for rendering to text/plain!" if self.links.size > 1
202
- text << self.links.first.to_text
203
- elsif standalone_action_instance?
204
- text << self.action.to_text
205
- else
206
- text << self.categories.collect { |category| category.to_text }.join("\n")
207
- text << "\n" if self.categories.any?
208
- raise "Only one resource allowed for rendering to text/plain!" if self.resources.size > 1
209
- text << self.resources.first.to_text if self.resources.any?
210
- text << self.links.collect { |link| link.to_text_link }.join("\n")
211
- text << self.action.to_text if self.action
212
- end
213
-
214
- text
215
- end
216
-
217
- def to_header
218
- header = Hashie::Mash.new
219
-
220
- if standalone_links?
221
- raise "Only one standalone link allowed for rendering to text/occi!" if self.links.size > 1
222
- header = self.links.first.to_header
223
- elsif standalone_action_instance?
224
- header = self.action.to_header
225
- else
226
- header['Category'] = self.categories.collect { |category| category.to_string }.join(',') if self.categories.any?
227
- raise "Only one resource allowed for rendering to text/occi!" if self.resources.size > 1
228
- header = self.class.header_merge(header, self.resources.first.to_header) if self.resources.any?
229
- header['Link'] = self.links.collect { |link| link.to_string }.join(',') if self.links.any?
230
- header = self.class.header_merge(header, self.action.to_header) if self.action
231
- end
232
-
233
- header
234
- end
235
-
236
- private
237
-
238
- def self.header_merge(target, other, separator=',')
239
- other.each_pair do |key,val|
240
- if target.key?(key)
241
- target[key] = "#{target[key]}#{separator}#{val}"
242
- else
243
- target[key] = val
244
- end
245
- end
246
- target
247
- end
248
-
249
- def standalone_links?
250
- !self.links.blank? && self.categories.blank? && self.resources.blank? && self.action.blank?
251
- end
252
-
253
- def standalone_action_instance?
254
- !self.action.blank? && self.categories.blank? && self.entities.blank?
255
- end
256
-
257
- def instance2cat(location)
258
- return location if location.start_with?('/') && location.end_with?('/')
259
- cat_relative_uri = "#{File.dirname(URI.parse(location).path)}/"
260
- raise "Supplied location is invalid! #{cat_relative_uri.inspect}" unless cat_relative_uri =~ /\/.+\//
261
- cat_relative_uri
262
- end
263
-
264
- end
265
- end
@@ -1,21 +0,0 @@
1
- module Occi
2
- module Core
3
- class Actions < Occi::Core::Categories
4
-
5
- private
6
-
7
- def convert(category)
8
- category = super category
9
-
10
- if category.kind_of? String
11
- scheme, term = category.split '#'
12
- scheme << '#'
13
- category = Occi::Core::Action.new(scheme, term)
14
- end
15
-
16
- category
17
- end
18
-
19
- end
20
- end
21
- end
@@ -1,411 +0,0 @@
1
- module Occi
2
- module Core
3
- class Attributes < Hashie::Mash
4
-
5
- attr_accessor :converted
6
-
7
- include Occi::Helpers::Inspect
8
- include Occi::Helpers::Comparators::Attributes
9
-
10
- def initialize(source_hash = {}, default = nil, &blk)
11
- raise ArgumentError, 'Source_hash is a mandatory argument!' unless source_hash
12
- raise ArgumentError, 'Source_hash must be a hash-like structure!' unless source_hash.kind_of?(Hash)
13
-
14
- # All internal Hashie::Mash elements in source_hash have to be re-typed
15
- # to Occi::Core::Attributes, so we have to rebuild the object from scratch
16
- source_hash = source_hash.to_hash unless source_hash.kind_of?(Occi::Core::Attributes)
17
-
18
- super(source_hash, default, &blk)
19
- end
20
-
21
- def converted?
22
- @converted||=false
23
- end
24
-
25
- def [](key)
26
- if key.to_s.include? '.'
27
- key, string = key.to_s.split('.', 2)
28
- attributes = super(key)
29
- raise Occi::Errors::AttributeMissingError,
30
- "Attribute with key #{key} not found" unless attributes
31
- attributes[string]
32
- else
33
- super(key)
34
- end
35
- end
36
-
37
- def []=(key, value)
38
- if key.to_s.include? '.'
39
- key, string = key.to_s.split('.', 2)
40
- super(key, Occi::Core::Attributes.new) unless self[key].kind_of? Occi::Core::Attributes
41
- self[key][string] = value
42
- else
43
- property_key = "_#{key.to_s}"
44
- validate_and_assign(key, value, property_key)
45
- end
46
- end
47
-
48
- def remove(attributes)
49
- attributes.keys.each do |key|
50
- next unless self.keys.include?(key)
51
-
52
- case self[key]
53
- when Occi::Core::Attributes
54
- self[key].remove attributes[key]
55
- else
56
- self.delete(key)
57
- end
58
- end
59
-
60
- self
61
- end
62
-
63
- def convert(attributes=Occi::Core::Attributes.new(self))
64
- attributes.each_pair do |key, value|
65
- next if key =~ /^_/
66
- case value
67
- when Occi::Core::Attributes
68
- value.convert!
69
- else
70
- attributes[key] = nil
71
- end
72
- end
73
-
74
- attributes.converted = true
75
- attributes
76
- end
77
-
78
- def convert!
79
- convert self
80
- end
81
-
82
- # @return [Hash] key value pair of full attribute names with their corresponding values
83
- def names
84
- hash = {}
85
- self.each_key do |key|
86
- next if key =~ /^_/
87
- if self[key].kind_of? Occi::Core::Attributes
88
- self[key].names.each_pair { |k, v| hash["#{key}.#{k}"] = v unless v.nil? }
89
- else
90
- hash[key] = self[key]
91
- end
92
- end
93
-
94
- hash
95
- end
96
-
97
- # @param [Hash] attributes
98
- # @return [Occi::Core::Attributes] parsed attributes with properties
99
- def self.parse_properties(hash)
100
- hash ||= {}
101
- raise Occi::Errors::ParserInputError,
102
- 'Hash must be a hash-like structure!' unless hash.respond_to?(:each_pair)
103
-
104
- attributes = Occi::Core::Attributes.new
105
- hash.each_pair do |key, value|
106
- if Occi::Core::Properties.contains_props?(value)
107
- value = value.to_hash if value.kind_of?(Hashie::Mash)
108
- attributes[key] = Occi::Core::Properties.new(value)
109
- else
110
- attributes[key] = self.parse_properties(value)
111
- end
112
- end
113
-
114
- attributes
115
- end
116
-
117
- # @param [Hash] attributes key value pair of full attribute names with their corresponding values
118
- # @return [Occi::Core::Attributes]
119
- def self.split(attributes)
120
- attribute = Attributes.new
121
- attributes.each do |name, value|
122
- key, _, rest = name.partition('.')
123
- if rest.blank?
124
- attribute[key] = value
125
- else
126
- attribute.merge! Attributes.new(key => self.split(rest => value))
127
- end
128
- end
129
-
130
- attribute
131
- end
132
-
133
- # @return [String]
134
- def to_string
135
- attributes = ';'
136
- attributes << to_array.join(';')
137
-
138
- attributes == ';' ? '' : attributes
139
- end
140
-
141
- # @return [String]
142
- def to_string_short
143
- any? ? ";attributes=#{names.keys.collect { |key| name_w_props(key) }.join(' ').inspect}" : ""
144
- end
145
-
146
- # @return [String]
147
- def to_text
148
- text = ""
149
- names.each_pair do |name, value|
150
- # TODO: find a better way to skip properties
151
- next if name.include? '._'
152
- case value
153
- when Occi::Core::Entity
154
- text << "\nX-OCCI-Attribute: #{name}=\"#{value.location}\""
155
- when Occi::Core::Category
156
- text << "\nX-OCCI-Attribute: #{name}=\"#{value.type_identifier}\""
157
- else
158
- text << "\nX-OCCI-Attribute: #{name}=#{value.inspect}"
159
- end
160
- end
161
-
162
- text
163
- end
164
-
165
- # @return [Array] of attributes put in an array
166
- def to_array
167
- attributes = []
168
-
169
- names.each_pair do |name, value|
170
- # TODO: find a better way to skip properties
171
- next if name.include? '._'
172
- case value
173
- when Occi::Core::Entity
174
- attributes << "#{name}=\"#{value.location}\""
175
- when Occi::Core::Category
176
- attributes << "#{name}=\"#{value.type_identifier}\""
177
- else
178
- attributes << "#{name}=#{value.inspect}"
179
- end
180
- end
181
-
182
- attributes
183
- end
184
-
185
- # @return [String] of attributes put in an array and then concatenated into a string
186
- def to_header
187
- to_array.join(',')
188
- end
189
-
190
- def to_json(*a)
191
- as_json(*a).to_json(*a)
192
- end
193
-
194
- # @param [Hash] options
195
- # @return [Hashie::Mash] json representation
196
- def as_json(options={})
197
- hash = Hashie::Mash.new
198
- self.each_pair do |key, value|
199
- next if key =~ /^_/
200
- # TODO: find a better way to skip properties
201
- next if key.start_with? '_'
202
-
203
- case value
204
- when Occi::Core::Attributes
205
- hash[key] = value.as_json if value && value.as_json.size > 0
206
- when Occi::Core::Entity
207
- hash[key] = value.to_s unless value.blank?
208
- when Occi::Core::Category
209
- hash[key] = value.to_s
210
- else
211
- hash[key] = value.as_json unless value.nil?
212
- end
213
- end
214
-
215
- hash
216
- end
217
-
218
- # @param [Occi::Core::Attributes] definitions
219
- # @param [true,false] set_defaults
220
- # @return [Occi::Core::Attributes] attributes with their defaults set
221
- def check(definitions, set_defaults = false)
222
- attributes = Occi::Core::Attributes.new(self)
223
- attributes.check!(definitions, set_defaults)
224
- attributes
225
- end
226
-
227
- # @param [Occi::Core::Attributes] definitions
228
- # @param [true,false] set_defaults
229
- # Assigns default values to attributes
230
- def check!(definitions, set_defaults = false)
231
- raise Occi::Errors::AttributeDefinitionsConvrertedError,
232
- "Definition attributes must not be converted" if definitions.converted?
233
-
234
- # Start with checking for missing attributes
235
- add_missing_attributes(self, definitions, set_defaults)
236
-
237
- # Then check all attributes against definitions
238
- check_wrt_definitions(self, definitions, set_defaults)
239
-
240
- # Delete remaining empty attributes
241
- delete_empty(self)
242
- end
243
-
244
- private
245
-
246
- def validate_and_assign(key, value, property_key)
247
- raise Occi::Errors::AttributeNameInvalidError,
248
- "Attribute names (as in \"#{key}\") must not begin with underscores" if key =~ /^_/
249
-
250
- case value
251
- when Occi::Core::Attributes
252
- add_to_hashie(key, value)
253
- when Occi::Core::Properties
254
- add_to_hashie(key, value.clone)
255
- add_to_hashie(property_key, value.clone)
256
- when Hash
257
- properties = Occi::Core::Properties.new(value)
258
- add_to_hashie(key, properties.clone)
259
- add_to_hashie(property_key, properties.clone)
260
- when Occi::Core::Entity
261
- match_type(value, 'string', self[property_key]) if self[property_key]
262
- add_to_hashie(key, value)
263
- when Occi::Core::Category
264
- match_type(value, 'string', self[property_key]) if self[property_key]
265
- add_to_hashie(key, value)
266
- when String
267
- value = interpret_string(value, self[property_key]) if self[property_key]
268
- add_to_hashie(key, value)
269
- when Numeric
270
- match_type(value, 'number', self[property_key]) if self[property_key]
271
- add_to_hashie(key, value)
272
- when FalseClass, TrueClass
273
- match_type(value, 'boolean', self[property_key]) if self[property_key]
274
- add_to_hashie(key, value)
275
- when NilClass
276
- add_to_hashie(key, value)
277
- else
278
- raise Occi::Errors::AttributeTypeError,
279
- "Value #{value} of type #{value.class} not supported as attribute"
280
- end
281
- end
282
-
283
- def add_to_hashie(*args)
284
- Hashie::Mash.instance_method(:[]=).bind(self).call(*args)
285
- end
286
-
287
- def interpret_string(value, property)
288
- if property.type == 'number' && (/^[.0-9]+$/ =~ value)
289
- value = (/^[0-9]+$/ =~ value) ? value.to_i : value.to_f
290
- match_type(value, 'number', property)
291
- elsif property.type == 'boolean'
292
- value = if value.casecmp("yes") == 0 || value.casecmp("true") == 0
293
- true
294
- elsif value.casecmp("no") == 0 || value.casecmp("false") == 0
295
- false
296
- else
297
- value
298
- end
299
-
300
- match_type(value, 'boolean', property)
301
- else
302
- match_type(value, 'string', property)
303
- end
304
-
305
- value
306
- end
307
-
308
- def match_type(value, value_type, property)
309
- raise Occi::Errors::AttributeTypeError,
310
- "Value #{value} derived from #{value.class} assigned " \
311
- "but attribute of type #{property.type} required" unless property.type == value_type
312
- match_pattern(property.pattern, value)
313
- end
314
-
315
- def match_pattern(pattern, value)
316
- return if pattern.blank?
317
-
318
- if Occi::Settings.verify_attribute_pattern && !Occi::Settings.compatibility
319
- raise Occi::Errors::AttributeTypeError,
320
- "Value #{value.to_s} does not match pattern #{pattern}" unless value.to_s.match "^#{pattern}$"
321
- else
322
- Occi::Log.debug "[#{self.class}] Skipping pattern checks on attributes, turn off " \
323
- "the compatibility mode and enable the attribute pattern check in settings!"
324
- end
325
- end
326
-
327
- def add_missing_attributes(attributes, definitions, set_defaults)
328
- definitions.each_key do |key|
329
- next if key =~ /^_/
330
-
331
- if definitions[key].kind_of? Occi::Core::Attributes
332
- attributes[key] = Occi::Core::Attributes.new if attributes[key].nil?
333
- add_missing_attributes(attributes[key], definitions[key], set_defaults)
334
- elsif attributes[key].nil?
335
- if definitions[key].default.nil?
336
- raise Occi::Errors::AttributeMissingError,
337
- "Required attribute #{key} not specified" if definitions[key].required
338
- elsif definitions[key].required || set_defaults
339
- attributes[key] = definitions[key]
340
- attributes[key] = definitions[key].default
341
- end
342
- else
343
- old_val = attributes[key]
344
- attributes[key] = definitions[key]
345
- attributes[key] = old_val
346
- end
347
- end
348
- end
349
-
350
- def check_wrt_definitions(attributes, definitions, set_defaults)
351
- attributes.each_key do |key|
352
- next if key =~ /^_/
353
-
354
- #Raise exception for attributes not defined at all
355
- raise Occi::Errors::AttributeNotDefinedError,
356
- "Attribute #{key} not found in definitions" unless definitions.key?(key)
357
-
358
- if attributes[key].kind_of? Occi::Core::Attributes
359
- check_wrt_definitions(attributes[key], definitions[key], set_defaults)
360
- else
361
- next if attributes[key].nil? # I will be removed in the next step
362
-
363
- #Check value types
364
- definitions[key].check_value_for_type(attributes[key], key)
365
-
366
- # Check patterns
367
- if definitions[key].pattern
368
- if Occi::Settings.verify_attribute_pattern && !Occi::Settings.compatibility
369
- raise Occi::Errors::AttributeTypeError,
370
- "Attribute #{key} with value #{attributes[key]} does not " \
371
- "match pattern #{definitions[key].pattern}" unless attributes[key].to_s.match "^#{definitions[key].pattern}$"
372
- else
373
- Occi::Log.debug "[#{self.class}] [#{key}] Skipping pattern checks on attributes, turn off " \
374
- "the compatibility mode and enable the attribute pattern check in settings!"
375
- end
376
- end
377
- end
378
- end
379
- end
380
-
381
- def delete_empty(attributes)
382
- attributes.each_key do |key|
383
- if attributes[key].kind_of? Occi::Core::Attributes
384
- delete_empty(attributes[key])
385
- else
386
- attributes.delete(key) if attributes[key].nil?
387
- end
388
- end
389
- end
390
-
391
- def name_w_props(attribute_name)
392
- return attribute_name if attribute_name.blank?
393
-
394
- parts = attribute_name.split('.')
395
- parts[parts.length - 1] = "_#{parts.last}"
396
- property_name = parts.join('.')
397
-
398
- return attribute_name unless self[property_name]
399
-
400
- props = []
401
- props << "immutable" if !self[property_name].mutable
402
- props << "required" if self[property_name].required
403
-
404
- attribute_name = "#{attribute_name}{#{props.join(' ')}}" unless props.empty?
405
-
406
- attribute_name
407
- end
408
-
409
- end
410
- end
411
- end