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
@@ -1,159 +1,127 @@
1
1
  module Occi
2
2
  module Core
3
- class Kind < Occi::Core::Category
4
-
5
- attr_accessor :entities, :parent, :actions
6
-
7
- # @param scheme [String ] The categorisation scheme.
8
- # @param term [String] Unique identifier of the Kind instance within the categorisation scheme.
9
- # @param title [String] The display name of an instance.
10
- # @param parent [Occi::Core::Kind,String] Another Kind instance which this Kind relates to.
11
- # @param actions [Occi::Core::Actions,Array] Set of Action instances defined by the Kind instance.
12
- # @param location [String] Location of the Kind instance.
13
- def initialize(scheme='http://schemas.ogf.org/occi/core#',
14
- term='kind',
15
- title=nil,
16
- attributes=Occi::Core::Attributes.new,
17
- parent=nil,
18
- actions=Occi::Core::Actions.new,
19
- location=nil)
20
- super(scheme, term, title, attributes)
21
- @parent = [parent].flatten.first
22
- @actions = Occi::Core::Actions.new(actions)
23
- @entities = Occi::Core::Entities.new
24
- @location = location.blank? ? "/#{term}/" : URI.parse(location).path
3
+ # Defines the classification system of the OCCI Core Model. The `Kind`
4
+ # instance represents the type identification mechanism for all `Entity`
5
+ # instances present in the model.
6
+ #
7
+ # @example
8
+ # Kind.new schema: 'http://schemas.ogf.org/occi/infrastructure#',
9
+ # term: 'compute',
10
+ # title: 'Compute'
11
+ #
12
+ # @attr parent [Kind] previous `Kind` in the OCCI kind hierarchy
13
+ # @attr actions [Set] list of `Action` instances applicable to this `Kind`
14
+ # @attr location [URI] protocol agnostic location of this `Kind` instance
15
+ #
16
+ # @author Boris Parak <parak@cesnet.cz>
17
+ class Kind < Category
18
+ include Helpers::Locatable
19
+
20
+ attr_accessor :parent, :actions
21
+ attr_writer :location
22
+
23
+ # Checks whether the given `Kind` instance is related
24
+ # to this instance. The given `Kind` instance must be
25
+ # included in the list of predecessors (see `#related`)
26
+ # to succeed.
27
+ #
28
+ # @param kind [Kind] suspected predecessor
29
+ # @return [TrueClass, FalseClass] result
30
+ def related?(kind)
31
+ return false unless kind
32
+ return true if kind == self
33
+ related.include? kind
25
34
  end
26
35
 
27
- # @param scheme [String] The categorisation scheme.
28
- # @param term [String] Unique identifier of the Category instance within the categorisation scheme.
29
- # @param parent [Array] Another Kind instance which this Kind relates to.
30
- # @return [Class] Ruby class with scheme as namespace, term as name and parent kind as super class.
31
- def self.get_class(scheme, term, parent=Occi::Core::Entity.kind)
32
- parent ||= Occi::Core::Entity.kind
33
- raise ArgumentError, 'Mandatory argument cannot be nil' unless scheme && term
34
-
35
- if parent.kind_of? Array
36
- parent = parent.first
37
- end
38
-
39
- if parent.to_s == 'http://schemas.ogf.org/occi/core#entity'
40
- parent = Occi::Core::Entity.kind
41
- elsif parent.to_s == 'http://schemas.ogf.org/occi/core#resource'
42
- parent = Occi::Core::Resource.kind
43
- elsif parent.to_s == 'http://schemas.ogf.org/occi/core#link'
44
- parent = Occi::Core::Link.kind
45
- elsif parent.kind_of? Occi::Core::Kind
46
- parent = parent
47
- else
48
- parent = self.get_class(*parent.to_s.split('#')).kind
49
- end
50
-
51
- term = self.sanitize_term(term) if Occi::Settings.compatibility
52
- raise ArgumentError, "Invalid characters in term #{term}" unless Occi::Core::Category.valid_term?(term)
53
-
54
- unless scheme.end_with? '#'
55
- scheme << '#'
56
- end
57
-
58
- uri = URI.parse(scheme)
59
-
60
- if uri.host == 'schemas.ogf.org'
61
- namespace = uri.path.reverse.chomp('/').reverse.split('/')
62
- else
63
- namespace = uri.host.split('.').reverse + uri.path.reverse.chomp('/').reverse.split('/')
64
- end
65
- namespace.inject(Object) do |mod, name|
66
- if mod.constants.collect { |sym| sym.to_s }.include? name.capitalize
67
- namespace = mod.const_get name.capitalize
68
- else
69
- namespace = mod.const_set name.capitalize, Module.new
70
- end
71
- end
72
-
73
- class_name = term.classify
74
- if namespace.const_defined? class_name
75
- klass = namespace.const_get class_name
76
- unless klass.ancestors.include? Occi::Core::Entity
77
- raise "OCCI Kind with type identifier #{scheme + term} could not be created as the corresponding class #{klass.to_s} already exists and is not derived from Occi::Core::Entity"
78
- end
79
- else
80
- klass = namespace.const_set class_name, Class.new(parent.entity_type)
81
- klass.kind = Occi::Core::Kind.new scheme=scheme,
82
- term=term,
83
- title=nil,
84
- attributes={},
85
- parent=parent
86
- end
87
-
88
- klass
36
+ # Checks whether the given `Kind` instance is related
37
+ # to this instance. The given `Kind` instance must be
38
+ # the immediate predecessor (see `#directly_related`)
39
+ # to succeed.
40
+ #
41
+ # @param kind [Kind] suspected predecessor
42
+ # @return [TrueClass, FalseClass] result
43
+ def directly_related?(kind)
44
+ return false unless kind
45
+ return true if kind == self
46
+ directly_related.include? kind
89
47
  end
90
48
 
91
- # Check if this Kind instance is related to another Kind instance.
49
+ # Transitively returns all predecessors of this `Kind` instance in
50
+ # a multi-element `Array`.
92
51
  #
93
- # @param kind [Occi::Core::Kind, String] Kind or Type Identifier of a Kind where relation should be checked.
94
- # @return [true,false]
95
- def related_to?(kind)
96
- to_s == kind.to_s || parent.to_s == kind.to_s \
97
- || \
98
- (parent.to_s == "http://schemas.ogf.org/occi/infrastructure#network" && kind.to_s == "http://schemas.ogf.org/occi/core#resource") \
99
- || \
100
- (parent.to_s == "http://schemas.ogf.org/occi/infrastructure#storage" && kind.to_s == "http://schemas.ogf.org/occi/core#resource") \
101
- || \
102
- (parent.to_s == "http://schemas.ogf.org/occi/infrastructure#compute" && kind.to_s == "http://schemas.ogf.org/occi/core#resource")
52
+ # @return [Array] list containing predecessors of this `Kind` instance
53
+ def related
54
+ return directly_related if hierarchy_root?
55
+ [parent, parent.related].flatten.compact
103
56
  end
104
57
 
105
- def entity_type
106
- self.class.get_class self.scheme, self.term, self.parent
58
+ # For compatibility reasons, returns the parent instance of this `Kind` in
59
+ # an `Array`. For hierarchy roots, returns only an empty `Array`.
60
+ #
61
+ # @return [Array] a list containing the parent `Kind` instance, if any
62
+ def directly_related
63
+ [parent].compact
107
64
  end
108
65
 
109
- # set location attribute of kind
110
- # @param [String] location
111
- def location=(location)
112
- location = URI.parse(location).path if location
113
- raise "Kind locations must end with a slash!" unless location.blank? || location =~ /^\/\S+\/$/
114
- @location = location
66
+ # Indicates whether this instance is the base of the OCCI kind
67
+ # hierarchy, i.e. there are no predecessors. This helps to
68
+ # calculate the relationship status correctly, see `#related`.
69
+ #
70
+ # @return [TrueClass, FalseClass] result
71
+ def hierarchy_root?
72
+ parent.nil?
115
73
  end
116
74
 
117
- def location
118
- @location ? @location.clone : nil
75
+ protected
76
+
77
+ # :nodoc:
78
+ def defaults
79
+ super.merge(parent: nil, actions: Set.new, location: nil)
119
80
  end
120
81
 
121
- def related
122
- [self.parent]
82
+ # :nodoc:
83
+ def sufficient_args!(args)
84
+ super
85
+ [:actions].each do |attr|
86
+ if args[attr].nil?
87
+ raise Occi::Core::Errors::MandatoryArgumentError, "#{attr} is a mandatory " \
88
+ "argument for #{self.class}"
89
+ end
90
+ end
123
91
  end
124
92
 
125
- # @param [Hash] options
126
- # @return [Hashie::Mash] json representation
127
- def as_json(options={})
128
- kind = Hashie::Mash.new
129
- kind.parent = self.parent.to_s if self.parent
130
- kind.related = self.related.join(' ').split(' ') if self.related.any?
131
- kind.actions = self.actions.join(' ').split(' ') if self.actions.any?
132
- kind.location = self.location if self.location
133
- kind.merge! super
134
- kind
93
+ # :nodoc:
94
+ def post_initialize(args)
95
+ super
96
+ @parent = args.fetch(:parent)
97
+ @actions = args.fetch(:actions)
98
+ @location = args.fetch(:location)
99
+
100
+ load_parent_attributes! if parent
135
101
  end
136
102
 
137
- # @return [String] string representation of the kind
138
- def to_string
139
- string = super
140
- string << ";rel=#{self.related.first.to_s.inspect}" if self.related.any?
141
- string << ";location=#{self.location.inspect}"
142
- string << self.attributes.to_string_short
143
- string << ";actions=#{self.actions.join(' ').inspect}" if self.actions.any?
144
- string
103
+ # :nodoc:
104
+ def load_parent_attributes!
105
+ attributes.merge!(parent.attributes) { |_, oldval, _| oldval }
145
106
  end
146
107
 
147
108
  private
148
109
 
149
- # Relaxed parser rules require additional checks on terms.
150
- def self.sanitize_term(term)
151
- sanitized = term.downcase.gsub(/[^a-z0-9-]/, '_').gsub(/_+/, '_').gsub(/^_|_$/, '')
152
- sanitized = "uuid_#{sanitized}" if sanitized.match(/^[0-9]/)
153
-
154
- sanitized
110
+ # Generates default location based on the already configured
111
+ # `term` attribute. Fails if `term` is not present.
112
+ #
113
+ # @example
114
+ # kind.term # => 'compute'
115
+ # kind.generate_location # => #<URI::Generic /compute/>
116
+ #
117
+ # @return [URI] generated location
118
+ def generate_location
119
+ if term.blank?
120
+ raise Occi::Core::Errors::MandatoryArgumentError,
121
+ 'Cannot generate default location without a `term`'
122
+ end
123
+ URI.parse "/#{term}/"
155
124
  end
156
-
157
125
  end
158
126
  end
159
127
  end
@@ -1,95 +1,70 @@
1
1
  module Occi
2
2
  module Core
3
- class Link < Occi::Core::Entity
4
-
5
- attr_accessor :rel, :source, :target
6
-
7
- self.attributes = Occi::Core::Attributes.new(Occi::Core::Entity.attributes)
8
- self.attributes['occi.core.target'] = {:mutable => true}
9
- self.attributes['occi.core.source'] = {:mutable => true, :required => true}
10
-
11
- self.kind = Occi::Core::Kind.new scheme='http://schemas.ogf.org/occi/core#',
12
- term='link',
13
- title='link',
14
- attributes=Occi::Core::Attributes.new(self.attributes),
15
- parent=Occi::Core::Entity.kind
3
+ # Implements the base class for all OCCI links, this
4
+ # class can be used directly to create link instances.
5
+ #
6
+ # @attr source [URI] link source as URI
7
+ # @attr source_kind [Occi::Core::Kind, NilClass] source kind or `nil` if unknown
8
+ # @attr target [URI] link target, may point outside of this domain
9
+ # @attr target_kind [Occi::Core::Kind, NilClass] target kind or `nil` if ourside the domain
10
+ #
11
+ # @author Boris Parak <parak@cesnet.cz>
12
+ class Link < Entity
13
+ attr_accessor :target_kind, :source_kind
14
+
15
+ # @return [URI] link source
16
+ def source
17
+ self['occi.core.source']
18
+ end
16
19
 
17
- # @param [String] kind
18
- # @param [String] mixins
19
- # @param [Occi::Core::Attributes] attributes
20
- # @param [Array] actions
21
- # @param [String] rel
22
- # @param [String,Occi::Core::Entity] target
23
- # @param [String,Occi::Core::Entity] source
24
- def initialize(kind=self.kind, mixins=[], attributes={}, actions=[], rel=Occi::Core::Link.type_identifier, target=nil, source=nil, location=nil)
25
- super(kind, mixins, attributes, actions, location)
26
- scheme, term = rel.to_s.split('#')
27
- @rel = Occi::Core::Kind.get_class(scheme, term).kind if scheme && term
28
- @source = source if source
29
- @target = target
20
+ # @param source [URI] link source
21
+ def source=(source)
22
+ self['occi.core.source'] = source.is_a?(String) ? URI.parse(source) : source
30
23
  end
31
24
 
32
- # @return [String] target attribute of the link
25
+ # @return [URI] link target
33
26
  def target
34
- @target ||= self.attributes.occi_.core_.target
35
- @target
27
+ self['occi.core.target']
36
28
  end
37
29
 
38
- # set target attribute of link
39
- # @param [String] target
30
+ # @param target [URI] link target
40
31
  def target=(target)
41
- self.attributes['occi.core.target'] = target.to_s
42
- @target = target.to_s
32
+ self['occi.core.target'] = target.is_a?(String) ? URI.parse(target) : target
43
33
  end
44
34
 
45
- # @return [String] source attribute of the link
46
- def source
47
- @source ||= self.attributes.occi_.core_.source
48
- @source
49
- end
35
+ # See `target_kind`
36
+ alias rel target_kind
37
+ alias rel= target_kind=
50
38
 
51
- # set source attribute of link
52
- # @param [String] source
53
- def source=(source)
54
- self.attributes['occi.core.source'] = source.to_s
55
- @source = source.to_s
56
- end
39
+ # See `#valid!` on `Occi::Core::Entity`.
40
+ def valid!
41
+ %i[source target].each do |attr|
42
+ next if send(attr)
43
+ raise Occi::Core::Errors::InstanceValidationError, "Missing valid #{attr}"
44
+ end
57
45
 
58
- # Runs check on attributes
59
- def check(set_defaults = false)
60
- raise ArgumentError, "Cannot run check on #{self.to_s.inspect} kind #{self.kind.to_s.inspect} without relation (the rel attribute) set!" unless @rel
61
46
  super
62
47
  end
63
48
 
64
- # @param [Hash] options
65
- # @return [Hashie::Mash] json representation
66
- def as_json(options={})
67
- link = super
68
- link.rel = @rel.to_s if @rel
69
- link.source = self.source.to_s unless self.source.to_s.blank?
70
- link.target = self.target.to_s if self.target
71
- link
72
- end
73
-
74
- # @return [String] text representation of link reference
75
- def to_string
76
- string = "<#{self.target.to_s}>"
77
- string << ";rel=#{@rel.to_s.inspect}"
78
- string << ";self=#{self.location.inspect}" if self.location
49
+ protected
79
50
 
80
- categories = [@kind.type_identifier].concat(@mixins.to_a.collect { |m| m.type_identifier })
81
- string << ";category=#{categories.join(' ').inspect}"
82
-
83
- string << @attributes.to_string
84
-
85
- string
51
+ # :nodoc:
52
+ def defaults
53
+ super.merge(source: nil, target: nil, target_kind: nil, source_kind: nil)
86
54
  end
87
55
 
88
- # @return [String] text representation of link
89
- def to_text_link
90
- "Link: #{self.to_string}"
56
+ # :nodoc:
57
+ def post_initialize(args)
58
+ super
59
+ if attributes['occi.core.source']
60
+ self.source = args.fetch(:source)
61
+ @source_kind = args.fetch(:source_kind)
62
+ end
63
+
64
+ return unless attributes['occi.core.target']
65
+ self.target = args.fetch(:target)
66
+ @target_kind = args.fetch(:target_kind)
91
67
  end
92
-
93
68
  end
94
69
  end
95
70
  end
@@ -1,81 +1,96 @@
1
1
  module Occi
2
2
  module Core
3
- class Mixin < Occi::Core::Category
3
+ # Defines the extension mechanism of the OCCI Core Model. The
4
+ # `Mixin` instance can be used to add `actions`, `attributes`,
5
+ # and custom features to existing `Entity` instances based on
6
+ # a specific `Kind` instance. A `Mixin` instance may depend
7
+ # on other `Mixin` instances (see `#depends`) and may be applied
8
+ # only to `Entity` instances based on specified `Kind` instances
9
+ # (see `#applies`). Some `Mixin` instances have special meaning
10
+ # defined in OCCI Standard documents.
11
+ #
12
+ # @attr actions [Set] list of `Action` instances attached to this mixin instance
13
+ # @attr depends [Set] list of `Mixin` instances on which this mixin depends
14
+ # @attr applies [Set] list of `Kind` instances to which this mixin can be applied
15
+ # @attr location [URI] protocol agnostic location of this mixin instance
16
+ #
17
+ # @author Boris Parak <parak@cesnet.cz>
18
+ class Mixin < Category
19
+ include Helpers::Locatable
4
20
 
5
- attr_accessor :entities, :depends, :actions, :applies
21
+ attr_accessor :actions, :depends, :applies
22
+ attr_writer :location
6
23
 
7
- # @param [String] scheme
8
- # @param [String] term
9
- # @param [String] title
10
- # @param [Occi::Core::Attributes,Hash,NilClass] attributes
11
- # @param [Occi::Core::Categories,Hash,NilClass] depends
12
- # @param [Occi::Core::Actions,Hash,NilClass] actions
13
- # @param [String] location
14
- # @param [Occi::Core::Kinds, NilClass] applies
15
- def initialize(scheme='http://schemas.ogf.org/occi/core#',
16
- term='mixin',
17
- title=nil,
18
- attributes=Occi::Core::Attributes.new,
19
- depends=Occi::Core::Dependencies.new,
20
- actions=Occi::Core::Actions.new,
21
- location='',
22
- applies=Occi::Core::Kinds.new)
23
-
24
- super(scheme, term, title, attributes)
25
- @depends = Occi::Core::Dependencies.new depends
26
- @actions = Occi::Core::Actions.new actions
27
- @entities = Occi::Core::Entities.new
28
- @location = location.blank? ? "/mixin/#{term}/" : URI.parse(location).path
29
- @applies = Occi::Core::Kinds.new applies
24
+ # Checks whether the given mixin is in the dependency
25
+ # chains of this instance. Checking for dependencies
26
+ # is strictly flat (no transitivity is applied). One
27
+ # `Mixin` instance may depend on multiple other instances.
28
+ #
29
+ # @param mixin [Mixin] candidate instance
30
+ # @return [TrueClass, FalseClass] result
31
+ def depends?(mixin)
32
+ return false unless depends && mixin
33
+ depends.include? mixin
30
34
  end
31
35
 
32
- # Check if this Mixin instance is related to another Mixin instance.
36
+ # Checks whether the given kind is in the applies
37
+ # set of this instance (i.e., this mixin can be applied
38
+ # to an `Entity` instance of the given kind). Checking
39
+ # for applicable kinds is strictly flat (no transitivity
40
+ # is applied). One `Mixin` instance may be applied to
41
+ # multiple kinds (`Entity` instances of the given kind).
33
42
  #
34
- # @param kind [Occi::Core::Mixin, String] Mixin or Type Identifier of a Mixin where relation should be checked.
35
- # @return [true,false]
36
- def related_to?(mixin)
37
- self.to_s == mixin.to_s || self.related.any? { |m| m.type_identifier == mixin.to_s }
43
+ # @param kind [Kind] candidate instance
44
+ # @return [TrueClass, FalseClass] result
45
+ def applies?(kind)
46
+ return false unless applies && kind
47
+ applies.include? kind
38
48
  end
39
49
 
40
- # set location attribute of kind
41
- # @param [String] location
42
- def location=(location)
43
- location = URI.parse(location).path if location
44
- raise "Mixin locations must end with a slash!" unless location.blank? || location =~ /^\/\S+\/$/
45
- @location = location
46
- end
50
+ protected
47
51
 
48
- def location
49
- @location ? @location.clone : nil
52
+ # :nodoc:
53
+ def defaults
54
+ super.merge(actions: Set.new, depends: Set.new, applies: Set.new, location: nil)
50
55
  end
51
56
 
52
- def related
53
- self.depends.to_a
57
+ # :nodoc:
58
+ def sufficient_args!(args)
59
+ super
60
+ %i[actions depends applies].each do |attr|
61
+ if args[attr].nil?
62
+ raise Occi::Core::Errors::MandatoryArgumentError, "#{attr} is a mandatory " \
63
+ "argument for #{self.class}"
64
+ end
65
+ end
54
66
  end
55
67
 
56
- # @param [Hash] options
57
- # @return [Hashie::Mash] json representation
58
- def as_json(options={})
59
- mixin = Hashie::Mash.new
60
- mixin.depends = self.depends.to_a.collect { |m| m.type_identifier } if self.depends.any?
61
- mixin.applies = self.applies.to_a.collect { |m| m.type_identifier } if self.applies.any?
62
- mixin.related = self.related.to_a.collect { |m| m.type_identifier } if self.related.any?
63
- mixin.actions = self.actions if self.actions.any?
64
- mixin.location = self.location if self.location
65
- mixin.merge! super
66
- mixin
68
+ # :nodoc:
69
+ def post_initialize(args)
70
+ super
71
+ @actions = args.fetch(:actions)
72
+ @depends = args.fetch(:depends)
73
+ @applies = args.fetch(:applies)
74
+ @location = args.fetch(:location)
67
75
  end
68
76
 
69
- # @return [String] text representation
70
- def to_string
71
- string = super
72
- string << ";rel=#{self.related.join(' ').inspect}" if self.related.any?
73
- string << ";location=#{self.location.inspect}"
74
- string << self.attributes.to_string_short
75
- string << ";actions=#{self.actions.join(' ').inspect}" if self.actions.any?
76
- string
77
- end
77
+ private
78
78
 
79
+ # Generates default location based on the already configured
80
+ # `term` attribute. Fails if `term` is not present.
81
+ #
82
+ # @example
83
+ # mixin.term # => 'compute'
84
+ # mixin.generate_location # => #<URI::Generic /mixin/compute/>
85
+ #
86
+ # @return [URI] generated location string
87
+ def generate_location
88
+ if term.blank?
89
+ raise Occi::Core::Errors::MandatoryArgumentError,
90
+ 'Cannot generate default location without a `term`'
91
+ end
92
+ URI.parse "/mixin/#{term}/"
93
+ end
79
94
  end
80
95
  end
81
96
  end