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
@@ -0,0 +1,341 @@
1
+ module Occi
2
+ module Core
3
+ # Implements a generic envelope for all OCCI-related categories. This
4
+ # class can be used directly for various reasons or, in a specific way,
5
+ # as an ancestor for custom classes providing `Model`-like functionality.
6
+ # Its primary purpose is to provide a tool for working with multiple
7
+ # sets of different categories, aid with their transport and validation.
8
+ #
9
+ # @attr categories [Set] set of categories associated with this model instance
10
+ #
11
+ # @author Boris Parak <parak@cesnet.cz>
12
+ class Model
13
+ include Yell::Loggable
14
+ include Helpers::ArgumentValidator
15
+ include Helpers::Renderable
16
+
17
+ attr_accessor :categories
18
+
19
+ # Constructs an instance with the given information. All arguments are
20
+ # optional and will default to empty `Set` instances if not provided.
21
+ #
22
+ # @example
23
+ # my_model = Occi::Core::Model.new
24
+ # my_model << mixin << kind << action
25
+ #
26
+ # @param args [Hash] arguments with model instance information
27
+ # @option args [Set] :categories set of categories associated with this model instance
28
+ def initialize(args = {})
29
+ pre_initialize(args)
30
+ default_args! args
31
+
32
+ @categories = args.fetch(:categories)
33
+
34
+ post_initialize(args)
35
+ end
36
+
37
+ # Collects everything present in this model and merges it into
38
+ # a single set. This will include kinds, mixins, and actions.
39
+ # The resulting set can be used, for example, in conjunction with the `<<`
40
+ # operator to create an independent copy of the model.
41
+ #
42
+ # @return [Set] content of this model as a new `Set` instance
43
+ def all
44
+ Set.new categories
45
+ end
46
+
47
+ # Collects all `Occi::Core::Kind` instances in this model.
48
+ #
49
+ # @return [Set] all `Occi::Core::Kind` instances from this model
50
+ def kinds
51
+ typed_set(categories, Occi::Core::Kind)
52
+ end
53
+
54
+ # Collects all `Occi::Core::Kind` instances specified
55
+ # as `parent` in one or more other kinds in this model.
56
+ # These instances may not appear in the model itself if
57
+ # it has not been successfully validated yet.
58
+ #
59
+ # @return [Set] parenting `Occi::Core::Kind` instances from this model
60
+ def parent_kinds
61
+ parents = kinds
62
+ parents.collect!(&:parent)
63
+ parents.reject!(&:nil?)
64
+ parents
65
+ end
66
+
67
+ # Collects all `Occi::Core::Mixin` instances in this model.
68
+ #
69
+ # @return [Set] all `Occi::Core::Mixin` instances from this model
70
+ def mixins
71
+ typed_set(categories, Occi::Core::Mixin)
72
+ end
73
+
74
+ # Collects all `Occi::Core::Mixin` instances specified
75
+ # in `depends` in one or more other mixins in this model.
76
+ # These instances may not appear in the model itself if
77
+ # it has not been successfully validated yet.
78
+ #
79
+ # @return [Set] depended on `Occi::Core::Mixin` instances from this model
80
+ def depended_on_mixins
81
+ depended_on = mixins
82
+ depended_on.collect!(&:depends)
83
+ depended_on.flatten!
84
+ depended_on.reject!(&:nil?)
85
+ depended_on
86
+ end
87
+
88
+ # Collects all `Occi::Core::Action` instances in this model.
89
+ #
90
+ # @return [Set] all `Occi::Core::Action` instances from this model
91
+ def actions
92
+ typed_set(categories, Occi::Core::Action)
93
+ end
94
+
95
+ # Collects all `Occi::Core::Action` instances specified
96
+ # in `actions` in one or more other mixins/kinds in this model.
97
+ # These instances may not appear in the model itself if
98
+ # it has not been successfully validated yet.
99
+ #
100
+ # @return [Set] associated `Occi::Core::Action` instances from this model
101
+ def associated_actions
102
+ associated = kinds + mixins
103
+ associated.collect!(&:actions)
104
+ associated.flatten!
105
+ associated.reject!(&:nil?)
106
+ associated
107
+ end
108
+
109
+ # Collects all `Occi::Core::Kind` instances related to the given instance.
110
+ #
111
+ # @param kind [Occi::Core::Kind] top-level kind
112
+ # @param options [Hash] look-up modifiers, currently only `directly: true`
113
+ # @return [Set] all instances related to the given instance
114
+ def find_related(kind, options = { directly: false })
115
+ raise ArgumentError, 'Kind is a mandatory argument' unless kind
116
+ method = options[:directly] ? :directly_related? : :related?
117
+ Set.new(kinds.select { |knd| knd.send(method, kind) })
118
+ end
119
+
120
+ # Collects all `Occi::Core::Mixin` instances dependent on the given instance.
121
+ #
122
+ # @param mixin [Occi::Core::Mixin] top-level mixin
123
+ # @return [Set] all instances dependent on the given instance
124
+ def find_dependent(mixin)
125
+ raise ArgumentError, 'Mixin is a mandatory argument' unless mixin
126
+ Set.new(mixins.select { |mxn| mxn.depends?(mixin) })
127
+ end
128
+
129
+ # Collects everything with the given location.
130
+ # This method looks for an explicit/full match on the location.
131
+ #
132
+ # @param location [URI] expected location
133
+ # @return [Set] set of results possibly containing a mix of types
134
+ def find_by_location(location)
135
+ filtered_set(
136
+ all.select { |elm| elm.respond_to?(:location) },
137
+ key: 'location', value: location
138
+ )
139
+ end
140
+
141
+ # Collects all `Occi::Core::Category` successors with the given identifier.
142
+ #
143
+ # @param identifier [String] expected identifier
144
+ # @return [Set] set of found categories
145
+ def find_by_identifier(identifier)
146
+ filtered_set(categories, key: 'identifier', value: identifier)
147
+ end
148
+
149
+ # See `find_by_identifier`. Returns first found object or raises an error.
150
+ #
151
+ # @param identifier [String] expected identifier
152
+ # @return [Object] found category
153
+ def find_by_identifier!(identifier)
154
+ found = categories.detect { |elm| elm.identifier == identifier }
155
+ raise Occi::Core::Errors::ModelLookupError, "Category #{identifier.inspect} not found in the model" unless found
156
+ found
157
+ end
158
+
159
+ # Collects all `Occi::Core::Category` successors with the given term.
160
+ #
161
+ # @param term [String] expected term
162
+ # @return [Set] set of found categories
163
+ def find_by_term(term)
164
+ filtered_set(categories, key: 'term', value: term)
165
+ end
166
+
167
+ # Collects all `Occi::Core::Category` successors with the given schema.
168
+ #
169
+ # @param schema [String] expected schema
170
+ # @return [Set] set of found categories
171
+ def find_by_schema(schema)
172
+ filtered_set(categories, key: 'schema', value: schema)
173
+ end
174
+
175
+ # Auto-assigns the given object to the appropriate internal set.
176
+ # Unknown objects will result in an `ArgumentError` error.
177
+ #
178
+ # @param object [Object] object to be assigned
179
+ # @return [Occi::Core::Model] self, for chaining purposes
180
+ def <<(object)
181
+ case object
182
+ when Occi::Core::Category
183
+ categories << object
184
+ else
185
+ raise ArgumentError, "Cannot automatically assign #{object.inspect}"
186
+ end
187
+
188
+ self
189
+ end
190
+ alias add <<
191
+
192
+ # Auto-removes the given object from the appropriate internal set.
193
+ # Unknown objects will result in an `ArgumentError` error.
194
+ #
195
+ # @param object [Object] object to be removed
196
+ # @return [Occi::Core::Model] self, for chaining purposes
197
+ def remove(object)
198
+ case object
199
+ when Occi::Core::Category
200
+ categories.delete object
201
+ else
202
+ raise ArgumentError, "Cannot automatically delete #{object.inspect}"
203
+ end
204
+
205
+ self
206
+ end
207
+
208
+ # Validates kinds, mixins, and actions stored in this model.
209
+ # Validity of each category is considered with regard to other categories.
210
+ # If you are looking for a more aggressive version raising validation errors,
211
+ # see `#valid!`.
212
+ #
213
+ # @return [TrueClass] on successful validation
214
+ # @return [FalseClass] on failed validation
215
+ def valid?
216
+ valid_helper? :valid!
217
+ end
218
+
219
+ # Validates kinds, mixins, and actions stored in this model.
220
+ # Validity of each category is considered with regard to other categories.
221
+ # This method will raise an error on the first invalid instance.
222
+ def valid!
223
+ valid_categories! # checking all identifiers
224
+ valid_parents! # parentage on kinds
225
+ valid_actions! # associated actions
226
+ valid_depends! # dependencies on mixins
227
+ valid_applies! # applicability on mixins
228
+ end
229
+
230
+ # Reports emptiness of the model.
231
+ #
232
+ # @return [TrueClass] if there are no categories
233
+ # @return [FalseClass] if there are some categories
234
+ def empty?
235
+ categories.empty?
236
+ end
237
+ alias nothing? empty?
238
+
239
+ # Loads OGF's OCCI Core Standard from `Occi::Core::Warehouse`.
240
+ #
241
+ # @example
242
+ # model = Occi::Core::Model.new
243
+ # model.load_core!
244
+ def load_core!
245
+ Occi::Core::Warehouse.bootstrap! self
246
+ end
247
+
248
+ # Returns an instance of `Occi::Core::InstanceBuilder` associated with this model.
249
+ #
250
+ # @return [Occi::Core::InstanceBuilder] instance of IB
251
+ def instance_builder
252
+ Occi::Core::InstanceBuilder.new(model: self)
253
+ end
254
+
255
+ protected
256
+
257
+ # :nodoc:
258
+ def sufficient_args!(args)
259
+ return if args[:categories]
260
+ raise Occi::Core::Errors::MandatoryArgumentError, '`categories` is a mandatory ' \
261
+ "argument for #{self.class}"
262
+ end
263
+
264
+ # :nodoc:
265
+ def defaults
266
+ { categories: Set.new }
267
+ end
268
+
269
+ # :nodoc:
270
+ def pre_initialize(args); end
271
+
272
+ # :nodoc:
273
+ def post_initialize(args); end
274
+
275
+ # :nodoc:
276
+ def typed_set(source, type)
277
+ Set.new(source.select { |elm| elm.is_a?(type) })
278
+ end
279
+
280
+ # :nodoc:
281
+ def filtered_set(source, filter)
282
+ raise ArgumentError, 'Filtering key is a mandatory argument' if filter[:key].blank?
283
+ Set.new(source.select { |elm| elm.send(filter[:key]) == filter[:value] })
284
+ end
285
+
286
+ # :nodoc:
287
+ def valid_helper?(method)
288
+ begin
289
+ send method
290
+ rescue Occi::Core::Errors::InstanceValidationError => ex
291
+ logger.warn "Instance invalid: #{ex.message}"
292
+ return false
293
+ rescue URI::InvalidURIError, Occi::Core::Errors::CategoryValidationError => ex
294
+ logger.warn "Category invalid: #{ex.message}"
295
+ return false
296
+ end
297
+
298
+ true
299
+ end
300
+
301
+ # :nodoc:
302
+ def valid_categories!
303
+ categories.each(&:valid!)
304
+ end
305
+
306
+ # :nodoc:
307
+ def valid_parents!
308
+ report_diff!('kinds') { parent_kinds - kinds }
309
+ end
310
+
311
+ # :nodoc:
312
+ def valid_depends!
313
+ report_diff!('mixins') { depended_on_mixins - mixins }
314
+ end
315
+
316
+ # :nodoc:
317
+ def valid_applies!
318
+ not_applicable = mixins.select { |mxn| mxn.applies.blank? }
319
+ return if not_applicable.empty?
320
+ logger.warn 'The following mixins are not applicable to any entity sub-type: ' \
321
+ "#{not_applicable.collect(&:identifier).inspect}"
322
+ end
323
+
324
+ # :nodoc:
325
+ def valid_actions!
326
+ report_diff!('actions') { associated_actions - actions }
327
+ end
328
+
329
+ # :nodoc:
330
+ def report_diff!(type)
331
+ raise 'You have to provide a diff block!' unless block_given?
332
+ diff = yield
333
+ return if diff.empty?
334
+
335
+ raise Occi::Core::Errors::CategoryValidationError,
336
+ "The following #{type} have been referenced but not defined: " \
337
+ "#{diff.to_a.collect(&:identifier).inspect}"
338
+ end
339
+ end
340
+ end
341
+ end
File without changes
@@ -0,0 +1,168 @@
1
+ module Occi
2
+ module Core
3
+ module Parsers
4
+ # Implementes base components necessary to parse all renderings.
5
+ #
6
+ # @attr model [Occi::Core::Model, Occi::Infrastructure::Model] model to use as a primary reference point
7
+ # @attr media_type [String] type of content to parse
8
+ #
9
+ # @abstract Not for direct use.
10
+ # @author Boris Parak <parak@cesnet.cz>
11
+ class BaseParser
12
+ include Yell::Loggable
13
+ include Helpers::ArgumentValidator
14
+ include Helpers::ErrorHandler
15
+
16
+ # Media type constants
17
+ MEDIA_TYPES = [].freeze
18
+
19
+ attr_accessor :model, :media_type
20
+
21
+ # Constructs an instance of the parser that will use a particular model as the reference for every
22
+ # parsed instance. Only instances allowed by the model will be successfuly parsed. In case of
23
+ # `Occi::Core::Category` instances, only identifiers are parsed and existing instances from the model
24
+ # are returned.
25
+ #
26
+ # @param args [Hash] constructor arguments in a Hash
27
+ # @option args [Occi::Core::Model] :model model to use as a primary reference point
28
+ # @option args [String] :media_type type of content to parse
29
+ def initialize(args = {})
30
+ pre_initialize(args)
31
+ default_args! args
32
+
33
+ @model = args.fetch(:model)
34
+ @media_type = args.fetch(:media_type)
35
+
36
+ post_initialize(args)
37
+ end
38
+
39
+ # Parses entities from the given body/headers. Only kinds, mixins, and actions already declared
40
+ # in the model are allowed.
41
+ #
42
+ # @param body [String] raw `String`-like body as provided by the transport protocol
43
+ # @param headers [Hash] raw headers as provided by the transport protocol
44
+ # @param expectation [Class] expected class of the returned instance(s)
45
+ # @return [Set] set of instances
46
+ def entities(_body, _headers, _expectation = nil)
47
+ raise Occi::Core::Errors::ParserError, 'This method needs to be implemented in subclasses'
48
+ end
49
+
50
+ # See `#entities`.
51
+ def resources(body, headers)
52
+ entities body, headers, Occi::Core::Resource
53
+ end
54
+
55
+ # See `#entities`.
56
+ def links(body, headers)
57
+ entities body, headers, Occi::Core::Link
58
+ end
59
+
60
+ # Parses action instances from the given body/headers. Only actions already declared in the model are
61
+ # allowed.
62
+ #
63
+ # @param body [String] raw `String`-like body as provided by the transport protocol
64
+ # @param headers [Hash] raw headers as provided by the transport protocol
65
+ # @return [Set] set of parsed instances
66
+ def action_instances(_body, _headers)
67
+ raise Occi::Core::Errors::ParserError, 'This method needs to be implemented in subclasses'
68
+ end
69
+
70
+ # Parses categories from the given body/headers and returns corresponding instances
71
+ # from the known model.
72
+ #
73
+ # @param body [String] raw `String`-like body as provided by the transport protocol
74
+ # @param headers [Hash] raw headers as provided by the transport protocol
75
+ # @param expectation [Class] expected class of the returned instance(s)
76
+ # @return [Set] set of instances
77
+ def categories(_body, _headers, _expectation = nil)
78
+ raise Occi::Core::Errors::ParserError, 'This method needs to be implemented in subclasses'
79
+ end
80
+
81
+ # See `#categories`.
82
+ def kinds(body, headers)
83
+ categories body, headers, Occi::Core::Kind
84
+ end
85
+
86
+ # See `#categories`.
87
+ def mixins(body, headers)
88
+ categories body, headers, Occi::Core::Mixin
89
+ end
90
+
91
+ # See `#categories`.
92
+ def actions(body, headers)
93
+ categories body, headers, Occi::Core::Action
94
+ end
95
+
96
+ # Checks whether the given media type is supported by this
97
+ # parser instance.
98
+ #
99
+ # @param media_type [String] media type string as provided by the transport protocol
100
+ # @return [TrueClass] if supported
101
+ # @return [FalseClass] if not supported
102
+ def parses?(media_type)
103
+ self.media_type == media_type
104
+ end
105
+
106
+ # Looks up the given category identifier in the model. Unsuccessfull lookup will raise an error, as will an
107
+ # unexpected class of the found instance.
108
+ #
109
+ # @param identifier [String] category identifier to look up in the model
110
+ # @param klass [Class] expected class (raises error otherwise)
111
+ # @return [Object] found instance
112
+ def lookup(identifier, klass)
113
+ found = handle(Occi::Core::Errors::ParsingError) { model.find_by_identifier!(identifier) }
114
+ unless found.is_a?(klass)
115
+ raise Occi::Core::Errors::ParsingError, "#{self.class} -> #{identifier.inspect} isn't #{klass}"
116
+ end
117
+ found
118
+ end
119
+
120
+ class << self
121
+ # Returns a list of supported media types for this parser.
122
+ #
123
+ # @return [Array] list of supported media types
124
+ def media_types
125
+ self::MEDIA_TYPES
126
+ end
127
+
128
+ # Checks whether the given media type is supported by this
129
+ # parser.
130
+ #
131
+ # @param media_type [String] media type string as provided by the transport protocol
132
+ # @return [TrueClass] if supported
133
+ # @return [FalseClass] if not supported
134
+ def parses?(media_type)
135
+ media_types.include? media_type
136
+ end
137
+ end
138
+
139
+ protected
140
+
141
+ # :nodoc:
142
+ def sufficient_args!(args)
143
+ %i[model media_type].each do |attr|
144
+ unless args[attr]
145
+ raise Occi::Core::Errors::MandatoryArgumentError, "#{attr} is a mandatory " \
146
+ "argument for #{self.class}"
147
+ end
148
+ end
149
+ end
150
+
151
+ # :nodoc:
152
+ def defaults
153
+ { model: nil, media_type: nil }
154
+ end
155
+
156
+ # :nodoc:
157
+ def pre_initialize(args); end
158
+
159
+ # :nodoc:
160
+ def post_initialize(args)
161
+ return if media_type.include?(args[:media_type])
162
+ raise Occi::Core::Errors::ParserError, "Media type #{args[:media_type].inspect} is not supported " \
163
+ "by instances of this parser, only #{media_type.inspect}"
164
+ end
165
+ end
166
+ end
167
+ end
168
+ end
File without changes
@@ -0,0 +1,36 @@
1
+ module Occi
2
+ module Core
3
+ module Parsers
4
+ module Json
5
+ # Static parsing class responsible for extracting action instances from JSON.
6
+ # Class supports 'application/json' via `json`. No other formats are supported.
7
+ #
8
+ # @author Boris Parak <parak@cesnet.cz>
9
+ class ActionInstance
10
+ include Yell::Loggable
11
+ include Helpers::ErrorHandler
12
+ extend Helpers::RawJsonParser
13
+
14
+ class << self
15
+ # Parses action instances. Internal references between objects are converted from strings
16
+ # to actual objects. Actions have to be declared in the provided model.
17
+ #
18
+ # @param body [String] JSON body for parsing
19
+ # @param model [Occi::Core::Model] model with existing categories
20
+ # @return [Occi::Core::ActionInstance] action instance
21
+ def json(body, model)
22
+ parsed = raw_hash(body)
23
+ ep = Entity.new(model: model)
24
+
25
+ action = handle(Occi::Core::Errors::ParsingError) { model.find_by_identifier!(parsed[:action]) }
26
+ ai = Occi::Core::ActionInstance.new(action: action)
27
+ ep.set_attributes!(ai.attributes, parsed[:attributes]) if parsed[:attributes]
28
+
29
+ ai
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,113 @@
1
+ module Occi
2
+ module Core
3
+ module Parsers
4
+ module Json
5
+ # Static parsing class responsible for extracting categories from JSON.
6
+ # Class supports 'application/json' via `json`. No other formats are supported.
7
+ #
8
+ # @author Boris Parak <parak@cesnet.cz>
9
+ class Category
10
+ include Yell::Loggable
11
+ include Helpers::ErrorHandler
12
+ extend Helpers::ParserDereferencer
13
+ extend Helpers::RawJsonParser
14
+
15
+ # Typecasting lambdas
16
+ TYPECASTER_HASH = {
17
+ 'boolean' => Boolean,
18
+ 'string' => String,
19
+ 'number' => Numeric,
20
+ 'array' => Array,
21
+ 'object' => Hash
22
+ }.freeze
23
+
24
+ # Hash constants for ParserDereferencer
25
+ PARENT_KEY = :parent
26
+ APPLIES_KEY = :applies
27
+ DEPENDS_KEY = :depends
28
+
29
+ class << self
30
+ # Parses categories into instances of subtypes of `Occi::Core::Category`. Internal references
31
+ # between objects are converted from strings to actual objects. Categories provided in the model
32
+ # will be reused but have to be declared in the parsed model as well.
33
+ #
34
+ # @param body [String] JSON body for parsing
35
+ # @param model [Occi::Core::Model] model with existing categories
36
+ # @param full [Boolean] dereference categories
37
+ # @return [Occi::Core::Model] model with all known category instances
38
+ def json(body, model, full = true)
39
+ parsed = raw_hash(body)
40
+
41
+ instantiate_hashes! parsed, model
42
+ return model unless full
43
+
44
+ raw_categories = [parsed[:kinds], parsed[:mixins]].flatten.compact
45
+ dereference_identifiers! model.categories, raw_categories
46
+
47
+ model
48
+ end
49
+
50
+ # :nodoc:
51
+ def instantiate_hashes!(raw, model)
52
+ raw[:kinds].each { |k| model << instatiate_hash(k, Occi::Core::Kind) } if raw[:kinds]
53
+ raw[:mixins].each { |k| model << instatiate_hash(k, Occi::Core::Mixin) } if raw[:mixins]
54
+ raw[:actions].each { |k| model << instatiate_hash(k, Occi::Core::Action) } if raw[:actions]
55
+ end
56
+
57
+ # :nodoc:
58
+ def instatiate_hash(raw, klass)
59
+ obj = klass.new(
60
+ term: raw[:term], schema: raw[:scheme], title: raw[:title],
61
+ attributes: attribute_definitions(raw[:attributes])
62
+ )
63
+
64
+ if obj.respond_to?(:location)
65
+ obj.location = handle(Occi::Core::Errors::ParsingError) { URI.parse(raw[:location]) }
66
+ end
67
+
68
+ obj
69
+ end
70
+
71
+ # :nodoc:
72
+ def attribute_definitions(raw)
73
+ return {} if raw.blank?
74
+
75
+ attr_defs = {}
76
+ raw.each_pair do |k, v|
77
+ def_hsh = typecast(v)
78
+ unless def_hsh[:type]
79
+ raise Occi::Core::Errors::ParsingError, "#{self} -> Attribute #{k.to_s.inspect} has no type"
80
+ end
81
+ attr_defs[k.to_s] = Occi::Core::AttributeDefinition.new def_hsh
82
+ end
83
+
84
+ attr_defs
85
+ end
86
+
87
+ # :nodoc:
88
+ def typecast(hash)
89
+ hash = hash.clone
90
+ hash[:type] = TYPECASTER_HASH[hash[:type]]
91
+ hash[:pattern] = handle(Occi::Core::Errors::ParsingError) { Regexp.new(hash[:pattern]) } if hash[:pattern]
92
+ hash
93
+ end
94
+
95
+ # :nodoc:
96
+ def lookup_applies_references!(mixin, derefd, parsed_rel)
97
+ return if parsed_rel.blank?
98
+ parsed_rel.each { |kind| mixin.applies << first_or_die(derefd, kind) }
99
+ end
100
+
101
+ # :nodoc:
102
+ def lookup_depends_references!(mixin, derefd, parsed_rel)
103
+ return if parsed_rel.blank?
104
+ parsed_rel.each { |mxn| mixin.depends << first_or_die(derefd, mxn) }
105
+ end
106
+
107
+ private :lookup_applies_references!, :lookup_depends_references!
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end