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,11 @@
1
+ module Occi
2
+ module Core
3
+ module Errors
4
+ # Custom error class indicating parsing failures on
5
+ # various renderings.
6
+ #
7
+ # @author Boris Parak <parak@cesnet.cz>
8
+ class ParsingError < StandardError; end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Occi
2
+ module Core
3
+ module Errors
4
+ # Custom error class indicating internal renderer
5
+ # errors or non-compliance with the expected interface.
6
+ #
7
+ # @author Boris Parak <parak@cesnet.cz>
8
+ class RendererError < StandardError; end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Occi
2
+ module Core
3
+ module Errors
4
+ # Custom error class indicating rendering failures on
5
+ # various renderable instances.
6
+ #
7
+ # @author Boris Parak <parak@cesnet.cz>
8
+ class RenderingError < StandardError; end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Occi
2
+ module Core
3
+ module Errors
4
+ # Custom error class indicating validation failures on
5
+ # various objects.
6
+ #
7
+ # @author Boris Parak <parak@cesnet.cz>
8
+ class ValidationError < StandardError; end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module Occi
2
+ module Core
3
+ # Wrapper for all custom error classes. For details on intended
4
+ # use, see specific error classes within this module.
5
+ module Errors; end
6
+ end
7
+ end
8
+
9
+ Dir[File.join(File.dirname(__FILE__), 'errors', '*.rb')].each { |file| require file.gsub('.rb', '') }
File without changes
@@ -0,0 +1,27 @@
1
+ module Occi
2
+ module Core
3
+ module Helpers
4
+ # Introduces argument validation capabilities to every receiver
5
+ # class. Should be used via the `include` or `extend` keywords.
6
+ #
7
+ # @author Boris Parak <parak@cesnet.cz>
8
+ module ArgumentValidator
9
+ # :nodoc:
10
+ def default_args!(args)
11
+ args.merge!(defaults) { |_, oldval, _| oldval }
12
+ sufficient_args!(args)
13
+ end
14
+
15
+ # :nodoc:
16
+ def sufficient_args!(args); end
17
+
18
+ # :nodoc:
19
+ def defaults
20
+ {}
21
+ end
22
+
23
+ private :defaults, :sufficient_args!, :default_args!
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ module Occi
2
+ module Core
3
+ module Helpers
4
+ # Introduces attributes accessor as a shortcut to
5
+ # getting to the `attributes` values inside the
6
+ # receiver.
7
+ #
8
+ # @author Boris Parak <parak@cesnet.cz>
9
+ module AttributesAccessor
10
+ # :nodoc:
11
+ def [](key)
12
+ attributes[key]
13
+ end
14
+
15
+ # :nodoc:
16
+ def []=(key, val)
17
+ attributes[key] = val
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ module Occi
2
+ module Core
3
+ module Helpers
4
+ # Introduces additional error handling functions to the receiver
5
+ # class and its instnaces.
6
+ #
7
+ # @author Boris Parak <parak@cesnet.cz>
8
+ module ErrorHandler
9
+ # Wraps potential exceptions raised in the given block in the specified
10
+ # exception class. Internal exception can be later exposed via `Exception#cause`.
11
+ #
12
+ # @param klass [Class] raise error of this class if necessary
13
+ def handle(klass)
14
+ raise 'You have to provide a block' unless block_given?
15
+ begin
16
+ yield # do whatever you need to do
17
+ rescue => ex
18
+ raise klass, ex.message
19
+ end
20
+ end
21
+
22
+ # :nodoc:
23
+ def self.included(klass)
24
+ klass.extend self
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,149 @@
1
+ module Occi
2
+ module Core
3
+ module Helpers
4
+ # Introduces hash dereferencing capabilities to `Hash`. This allowes
5
+ # hash instances containing `Occi::Core::Category` sub-types by
6
+ # identifier and `Occi::Core::AttributeDefinition` instances by name to be
7
+ # converted into proper objects.
8
+ #
9
+ # @author Boris Parak <parak@cesnet.cz>
10
+ module HashDereferencer
11
+ # Replaces all references to existing categories with actual instances from
12
+ # from the given model. Similar processing is done on attribute definitions
13
+ # referenced by attribute names.
14
+ #
15
+ # @param klass [Class] klass serialized in this hash
16
+ # @param model [Occi::Core::Model] model instance for dereferencing (category look-up)
17
+ # @param attribute_definitions [Hash] hash with known attribute definitions for dereferencing
18
+ # @return [Integer] number of changes made when dereferencing
19
+ def dereference_with!(klass, model, attribute_definitions)
20
+ unless model && attribute_definitions
21
+ raise 'Both `model` and `attribute_definitions` are ' \
22
+ 'required for dereferencing'
23
+ end
24
+
25
+ send(
26
+ "dereference_#{klass.to_s.demodulize.downcase}_with!",
27
+ model, attribute_definitions
28
+ )
29
+ end
30
+
31
+ # Replaces all references to existing categories with actual instances from
32
+ # from the given model. Similar processing is done on attribute definitions
33
+ # referenced by attribute names.
34
+ #
35
+ # @param model [Occi::Core::Model] model instance for dereferencing (category look-up)
36
+ # @param attribute_definitions [Hash] hash with known attribute definitions for dereferencing
37
+ # @return [Integer] number of changes made when dereferencing
38
+ def dereference_category_with!(model, attribute_definitions)
39
+ changed = 0
40
+
41
+ unless self[:actions].blank?
42
+ self[:actions].map! { |action| dereference_via_model(action, model) }
43
+ changed += self[:actions].count
44
+ end
45
+ self[:actions] = Set.new(self[:actions])
46
+ changed += dereference_attribute_definitions_with!(attribute_definitions)
47
+
48
+ changed
49
+ end
50
+
51
+ # Replaces all name-only references to existing attribute definitions with actual instances from
52
+ # from the given hash.
53
+ #
54
+ # @param attribute_definitions [Hash] hash with known attribute definitions for dereferencing
55
+ # @return [Integer] number of changes made when dereferencing
56
+ def dereference_attribute_definitions_with!(attribute_definitions)
57
+ return 0 if self[:attributes].blank?
58
+
59
+ new_attributes = {}
60
+ self[:attributes].each do |attribute|
61
+ new_attributes[attribute] = dereference_via_hash(attribute, attribute_definitions)
62
+ end
63
+ self[:attributes] = new_attributes
64
+
65
+ self[:attributes].count
66
+ end
67
+
68
+ # Replaces all references to existing categories with actual instances from
69
+ # from the given model. Similar processing is done on attribute definitions
70
+ # referenced by attribute names.
71
+ #
72
+ # @param model [Occi::Core::Model] model instance for dereferencing (category look-up)
73
+ # @param attribute_definitions [Hash] hash with known attribute definitions for dereferencing
74
+ # @return [Integer] number of changes made when dereferencing
75
+ def dereference_kind_with!(model, attribute_definitions)
76
+ changed = 0
77
+
78
+ if self[:parent]
79
+ self[:parent] = dereference_via_model(self[:parent], model)
80
+ changed += 1
81
+ end
82
+ changed += dereference_category_with!(model, attribute_definitions)
83
+
84
+ changed
85
+ end
86
+
87
+ # Replaces all hashes with attribute definitions with valid instnaces of
88
+ # `Occi::Core::AttributeDefinition`.
89
+ #
90
+ # @param model [Occi::Core::Model] model instance for dereferencing (category look-up)
91
+ # @param attribute_definitions [Hash] hash with known attribute definitions for dereferencing
92
+ # @return [Integer] number of changes made when dereferencing
93
+ def dereference_action_with!(_model, _attribute_definitions)
94
+ return 0 if self[:attributes].blank?
95
+ # TODO: handle attributes referenced by name only
96
+ self[:attributes].each_pair do |key, val|
97
+ self[:attributes][key] = Occi::Core::AttributeDefinition.new(val.symbolize_keys)
98
+ end
99
+ self[:attributes].count
100
+ end
101
+
102
+ # Replaces all references to existing categories with actual instances from
103
+ # from the given model. Similar processing is done on attribute definitions
104
+ # referenced by attribute names.
105
+ #
106
+ # @param model [Occi::Core::Model] model instance for dereferencing (category look-up)
107
+ # @param attribute_definitions [Hash] hash with known attribute definitions for dereferencing
108
+ # @return [Integer] number of changes made when dereferencing
109
+ def dereference_mixin_with!(model, attribute_definitions)
110
+ changed = 0
111
+
112
+ %i[depends applies].each do |symbol|
113
+ unless self[symbol].blank?
114
+ self[symbol].map! { |elm| dereference_via_model(elm, model) }
115
+ changed += self[symbol].count
116
+ end
117
+ self[symbol] = Set.new(self[symbol])
118
+ end
119
+ changed += dereference_category_with!(model, attribute_definitions)
120
+
121
+ changed
122
+ end
123
+
124
+ # Looks up the given category in the model. Raises error if no
125
+ # such category is found.
126
+ #
127
+ # @param identifier [String] category identifier
128
+ # @param model [Occi::Core::Model] model instance for dereferencing (category look-up)
129
+ # @return [Occi::Core::Category] instance located in the model
130
+ def dereference_via_model(identifier, model)
131
+ model.find_by_identifier!(identifier)
132
+ end
133
+
134
+ # Looks up the given attribute definition in the hash. Raises error if no
135
+ # such attribute definition is found.
136
+ #
137
+ # @param identifier [String] attribute identifier (name)
138
+ # @param hash [Hash] hash with known attribute definitions for dereferencing
139
+ # @return [Occi::Core::AttributeDefinition] definition located in the hash
140
+ def dereference_via_hash(identifier, hash)
141
+ raise "Attribute definition #{identifier.inspect} not found in the hash" unless hash[identifier]
142
+ hash[identifier]
143
+ end
144
+
145
+ private :dereference_via_hash, :dereference_via_model
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,135 @@
1
+ module Occi
2
+ module Core
3
+ module Helpers
4
+ # Introduces validation capabilities to every receiver
5
+ # class. Should be used via the `extend` keyword.
6
+ #
7
+ # @author Boris Parak <parak@cesnet.cz>
8
+ module IdentifierValidator
9
+ # Characters prohibited in `schema` attribute
10
+ PROHIBITED_SCHEMA_CHARS = %w[% & ? ! \\].freeze
11
+
12
+ # Definition of characters allowed in `term` attribute
13
+ REGEXP_TERM = /^([[:alpha:]]|[[:digit:]])([[:alpha:]]|[[:digit:]]|-|_)*$/
14
+
15
+ # Validates given `term` against the restrictions imposed by the
16
+ # OCCI specification. See `REGEXP_TERM` in this class for details.
17
+ #
18
+ # @example
19
+ # valid_term? 'a b' # => false
20
+ # valid_term? 'ab' # => true
21
+ #
22
+ # @param term [String] term candidate
23
+ # @return [TrueClass, FalseClass] result
24
+ def valid_term?(term)
25
+ begin
26
+ valid_term! term
27
+ rescue Occi::Core::Errors::CategoryValidationError => ex
28
+ logger.warn "#{self}: Term validation failed with #{ex.message}" if respond_to?(:logger)
29
+ return false
30
+ end
31
+
32
+ true
33
+ end
34
+
35
+ # Similar to `::valid_term?`, raises an `Occi::Core::Errors::CategoryValidationError`
36
+ # error in case of failure.
37
+ #
38
+ # @param term [String] term candidate
39
+ def valid_term!(term)
40
+ validation_result = REGEXP_TERM.match(term)
41
+
42
+ return if validation_result
43
+ raise Occi::Core::Errors::CategoryValidationError,
44
+ "Term #{term.inspect} does not match #{REGEXP_TERM.inspect}"
45
+ end
46
+
47
+ # Validates given `schema` against the restrictions imposed by the
48
+ # URI specification. See Ruby's `URI` class for details. On top of
49
+ # that, every schema must be terminated with '#'.
50
+ #
51
+ # @example
52
+ # valid_schema? '%^#%^' # => false
53
+ # valid_schema? 'http://example.org/test#' # => true
54
+ #
55
+ # @param schema [String] schema candidate
56
+ # @return [TrueClass, FalseClass] result
57
+ def valid_schema?(schema)
58
+ begin
59
+ valid_schema! schema
60
+ rescue URI::InvalidURIError, Occi::Core::Errors::CategoryValidationError => ex
61
+ logger.warn "#{self}: Schema validation failed with #{ex.message}" if respond_to?(:logger)
62
+ return false
63
+ end
64
+
65
+ true
66
+ end
67
+
68
+ # Similar to `::valid_schema?`, raises an `Occi::Core::Errors::CategoryValidationError`
69
+ # error in case of failure.
70
+ #
71
+ # @param schema [String] schema candidate
72
+ def valid_schema!(schema)
73
+ if schema.blank?
74
+ raise Occi::Core::Errors::CategoryValidationError,
75
+ "Schema #{schema.inspect} cannot be blank"
76
+ end
77
+ unless schema.end_with?('#')
78
+ raise Occi::Core::Errors::CategoryValidationError,
79
+ "Schema #{schema.inspect} must be terminated with '#'"
80
+ end
81
+
82
+ valid_uri! schema
83
+ prohibited_chars! schema
84
+ end
85
+
86
+ # Validates given `identifier` as a combination of rules for `term`
87
+ # and `schema`.
88
+ #
89
+ # @example
90
+ # valid_identifier? 'http://schema.org/test#a#b' # => false
91
+ # valid_identifier? 'http://schema.org/test#a' # => true
92
+ #
93
+ # @param identifier [String] identifier candidate
94
+ # @return [TrueClass, FalseClass] result
95
+ def valid_identifier?(identifier)
96
+ begin
97
+ valid_identifier! identifier
98
+ rescue URI::InvalidURIError, Occi::Core::Errors::CategoryValidationError => ex
99
+ logger.warn "#{self}: Identifier validation failed with #{ex.message}" if respond_to?(:logger)
100
+ return false
101
+ end
102
+
103
+ true
104
+ end
105
+
106
+ # Similar to `::valid_identifier?`, raises an `Occi::Core::Errors::CategoryValidationError`
107
+ # error in case of failure.
108
+ #
109
+ # @param identifier [String] identifier candidate
110
+ def valid_identifier!(identifier)
111
+ elements = identifier.split('#')
112
+ if elements.count != 2
113
+ raise Occi::Core::Errors::CategoryValidationError,
114
+ "Identifier #{identifier.inspect} is malformed"
115
+ end
116
+
117
+ valid_schema! "#{elements.first}#"
118
+ valid_term! elements.last
119
+ end
120
+
121
+ # :nodoc:
122
+ def valid_uri!(uri)
123
+ URI.split uri
124
+ end
125
+
126
+ # :nodoc:
127
+ def prohibited_chars!(schema)
128
+ PROHIBITED_SCHEMA_CHARS.each do |char|
129
+ raise "Schema #{schema.inspect} contains prohibited character #{char.inspect}" if schema.include?(char)
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,131 @@
1
+ module Occi
2
+ module Core
3
+ module Helpers
4
+ # Introduces instance attribute resetting functionality to
5
+ # the receiver. Provides methods for applying defaults and
6
+ # adding attributes on top of existing base attributes.
7
+ # `base_attributes` and `added_attributes` must be implemented
8
+ # in the receiver.
9
+ #
10
+ # @author Boris Parak <parak@cesnet.cz>
11
+ module InstanceAttributeResetter
12
+ # Shorthand for running `reset_attributes` with the `force` flag on.
13
+ # This method will force defaults from definitions in all available
14
+ # attributes. No longer defined attributes will be automatically removed.
15
+ def reset_attributes!
16
+ reset_attributes true
17
+ end
18
+
19
+ # Shorthand for running `reset_base_attributes` with the `force` flag on.
20
+ # This method will force defaults from definitions in all available
21
+ # attributes. No longer defined attributes will be kept unchanged.
22
+ def reset_base_attributes!
23
+ reset_base_attributes true
24
+ end
25
+
26
+ # Shorthand for running `reset_added_attributes` with the `force` flag on.
27
+ # This method will force defaults from definitions in all available
28
+ # attributes. No longer defined attributes will be kept unchanged.
29
+ def reset_added_attributes!
30
+ reset_added_attributes true
31
+ end
32
+
33
+ # Iterates over available attribute definitions and
34
+ # sets corresponding fields in `attributes`. When using the `force` flag, all
35
+ # existing attribute values will be replaced by defaults from definitions or
36
+ # reset to `nil`. No longer defined attributes will be automatically removed.
37
+ #
38
+ # @param force [TrueClass, FalseClass] forcibly change attribute values to defaults
39
+ def reset_attributes(force = false)
40
+ reset_base_attributes force
41
+ reset_added_attributes force
42
+ remove_undef_attributes
43
+ end
44
+
45
+ # Removes attributes (definition and value) if they are no longer defined
46
+ # for this instance. This is automatically called when invoking reset via
47
+ # `reset_attributes` or `reset_attributes!`, in all other cases it has to
48
+ # be triggered explicitly. Attributes without definitions will be removed
49
+ # as well.
50
+ #
51
+ # @return [Hash] updated attribute hash
52
+ def remove_undef_attributes
53
+ name_cache = attribute_names
54
+ attributes.keep_if { |key, value| name_cache.include?(key) && value && value.attribute_definition }
55
+ end
56
+
57
+ # Collects all available attribute names into a list. Without definitions
58
+ # or values.
59
+ #
60
+ # @return [Array] list available attribute names
61
+ def attribute_names
62
+ names = added_attributes.collect(&:keys)
63
+ names << base_attributes.keys
64
+ names.flatten!
65
+ names.compact!
66
+
67
+ names
68
+ end
69
+
70
+ # Iterates over available base attribute definitions and
71
+ # sets corresponding fields in `attributes`. When using the `force` flag, all
72
+ # existing attribute values will be replaced by defaults from definitions or
73
+ # reset to `nil`. No longer defined attributes will be kept unchanged.
74
+ #
75
+ # @param force [TrueClass, FalseClass] forcibly change attribute values to defaults
76
+ # @return [Array] list of processed attribute names
77
+ def reset_base_attributes(force = false)
78
+ processed_attrs = []
79
+
80
+ base_attributes.each_pair do |name, definition|
81
+ processed_attrs << name
82
+ reset_attribute(name, definition, force)
83
+ end
84
+
85
+ processed_attrs
86
+ end
87
+
88
+ # Iterates over available added attribute definitions and
89
+ # sets corresponding fields in `attributes`. When using the `force` flag, all
90
+ # existing attribute values will be replaced by defaults from definitions or
91
+ # reset to `nil`. No longer defined attributes will be kept unchanged.
92
+ #
93
+ # @param force [TrueClass, FalseClass] forcibly change attribute values to defaults
94
+ # @return [Array] list of processed attribute names
95
+ def reset_added_attributes(force = false)
96
+ processed_attrs = []
97
+
98
+ added_attributes.each do |attrs|
99
+ attrs.each_pair do |name, definition|
100
+ if processed_attrs.include?(name)
101
+ raise Occi::Core::Errors::AttributeDefinitionError,
102
+ "Attribute #{name.inspect} already modified by another mixin"
103
+ end
104
+ processed_attrs << name
105
+ reset_attribute(name, definition, force)
106
+ end
107
+ end
108
+
109
+ processed_attrs
110
+ end
111
+
112
+ # Sets corresponding attribute fields in `attributes`. When using the `force` flag, any
113
+ # existing attribute value will be replaced by the default from its definition or
114
+ # reset to `nil`.
115
+ #
116
+ # @param name [String] attribute name
117
+ # @param definition [AttributeDefinition] attribute definition
118
+ # @param force [TrueClass, FalseClass] forcibly change attribute value to default
119
+ def reset_attribute(name, definition, force)
120
+ if attributes[name]
121
+ attributes[name].attribute_definition = definition
122
+ else
123
+ attributes[name] = Attribute.new(nil, definition)
124
+ end
125
+
126
+ force ? attributes[name].default! : attributes[name].default
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,30 @@
1
+ module Occi
2
+ module Core
3
+ module Helpers
4
+ # Introduces instance attributes accessor as a shortcut to
5
+ # getting to the `attributes` values inside the receiver.
6
+ #
7
+ # @author Boris Parak <parak@cesnet.cz>
8
+ module InstanceAttributesAccessor
9
+ # :nodoc:
10
+ def [](key)
11
+ attribute?(key) ? attributes[key].value : nil
12
+ end
13
+
14
+ # :nodoc:
15
+ def attribute?(key)
16
+ !attributes[key].nil?
17
+ end
18
+
19
+ # :nodoc:
20
+ def []=(key, val)
21
+ unless attribute?(key)
22
+ raise Occi::Core::Errors::AttributeDefinitionError, 'Attribute named ' \
23
+ "#{key.inspect} has not been defined for #{self}"
24
+ end
25
+ attributes[key].value = val
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,40 @@
1
+ module Occi
2
+ module Core
3
+ module Helpers
4
+ # Introduces location-based capabilities to every receiver
5
+ # class. Provides methods to access set location value
6
+ # and generate default locations if necessary.
7
+ #
8
+ # @author Boris Parak <parak@cesnet.cz>
9
+ module Locatable
10
+ # Returns the location of this instance. Set location
11
+ # is preferred over the generated one. If no location is known
12
+ # one is generated from available information specific to
13
+ # this instance.
14
+ #
15
+ # @example
16
+ # obj.location # => #<URI::Generic /my_location/>
17
+ #
18
+ # @return [URI] instance location
19
+ def location
20
+ @location || generate_location
21
+ end
22
+
23
+ # Generates default location based on the already configured
24
+ # instance attribute(s). Fails if required attributes are not
25
+ # present.
26
+ #
27
+ # @example
28
+ # obj.generate_location # => #<URI::Generic /my_location/>
29
+ #
30
+ # @return [URI] generated location
31
+ # @abstract This method MUST be implemented in every 'locatable' class
32
+ def generate_location
33
+ raise "Cannot generate default location for #{self.class}, I don't know how"
34
+ end
35
+
36
+ protected :generate_location
37
+ end
38
+ end
39
+ end
40
+ end