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.
- checksums.yaml +4 -4
- data/.fasterer.yml +3 -0
- data/.gitignore +9 -16
- data/.rspec +1 -1
- data/.rubocop.yml +69 -0
- data/.travis.yml +27 -0
- data/AUTHORS +8 -6
- data/CHANGELOG.md +0 -0
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/README.md +25 -170
- data/Rakefile +25 -17
- data/examples/initialize_model.rb +10 -0
- data/examples/parse_action_instance_json.rb +15 -0
- data/examples/parse_action_instance_text.rb +15 -0
- data/examples/parse_categories_json.rb +15 -0
- data/examples/parse_categories_text.rb +15 -0
- data/examples/parse_instance_json.rb +15 -0
- data/examples/parse_instance_text.rb +15 -0
- data/examples/parse_model_json.rb +9 -0
- data/examples/parse_model_text.rb +9 -0
- data/examples/render_action_instance_json.rb +17 -0
- data/examples/render_action_instance_text.rb +17 -0
- data/examples/render_instance_json.rb +20 -0
- data/examples/render_instance_text.rb +20 -0
- data/examples/render_model_json.rb +12 -0
- data/examples/render_model_text.rb +12 -0
- data/examples/rendering/action_instance.json +6 -0
- data/examples/rendering/action_instance.txt +2 -0
- data/examples/rendering/categories.json +78 -0
- data/examples/rendering/categories.txt +4 -0
- data/examples/rendering/instance.json +70 -0
- data/examples/rendering/instance.txt +12 -0
- data/examples/rendering/model.alt.json +1716 -0
- data/examples/rendering/model.json +785 -0
- data/examples/rendering/model.txt +68 -0
- data/lib/occi/core/action.rb +12 -26
- data/lib/occi/core/action_instance.rb +109 -65
- data/lib/occi/core/attribute.rb +136 -0
- data/lib/occi/core/attribute_definition.rb +269 -0
- data/lib/occi/core/category.rb +110 -83
- data/lib/occi/core/collection.rb +255 -0
- data/lib/occi/core/constants.rb +14 -0
- data/lib/occi/core/entity.rb +301 -195
- data/lib/occi/core/errors/.gitkeep +0 -0
- data/lib/occi/core/errors/attribute_definition_error.rb +11 -0
- data/lib/occi/core/errors/attribute_validation_error.rb +13 -0
- data/lib/occi/core/errors/category_validation_error.rb +13 -0
- data/lib/occi/core/errors/collection_lookup_error.rb +11 -0
- data/lib/occi/core/errors/instance_validation_error.rb +13 -0
- data/lib/occi/core/errors/mandatory_argument_error.rb +11 -0
- data/lib/occi/core/errors/model_lookup_error.rb +11 -0
- data/lib/occi/core/errors/parser_error.rb +11 -0
- data/lib/occi/core/errors/parsing_error.rb +11 -0
- data/lib/occi/core/errors/renderer_error.rb +11 -0
- data/lib/occi/core/errors/rendering_error.rb +11 -0
- data/lib/occi/core/errors/validation_error.rb +11 -0
- data/lib/occi/core/errors.rb +9 -0
- data/lib/occi/core/helpers/.gitkeep +0 -0
- data/lib/occi/core/helpers/argument_validator.rb +27 -0
- data/lib/occi/core/helpers/attributes_accessor.rb +22 -0
- data/lib/occi/core/helpers/error_handler.rb +29 -0
- data/lib/occi/core/helpers/hash_dereferencer.rb +149 -0
- data/lib/occi/core/helpers/identifier_validator.rb +135 -0
- data/lib/occi/core/helpers/instance_attribute_resetter.rb +131 -0
- data/lib/occi/core/helpers/instance_attributes_accessor.rb +30 -0
- data/lib/occi/core/helpers/locatable.rb +40 -0
- data/lib/occi/core/helpers/parser_dereferencer.rb +96 -0
- data/lib/occi/core/helpers/raw_json_parser.rb +18 -0
- data/lib/occi/core/helpers/renderable.rb +93 -0
- data/lib/occi/core/helpers/yaml_summoner.rb +44 -0
- data/lib/occi/core/helpers.rb +13 -0
- data/lib/occi/core/instance_builder.rb +162 -0
- data/lib/occi/core/kind.rb +100 -132
- data/lib/occi/core/link.rb +47 -72
- data/lib/occi/core/mixin.rb +76 -61
- data/lib/occi/core/model.rb +341 -0
- data/lib/occi/core/parsers/.gitkeep +0 -0
- data/lib/occi/core/parsers/base_parser.rb +168 -0
- data/lib/occi/core/parsers/json/.gitkeep +0 -0
- data/lib/occi/core/parsers/json/action_instance.rb +36 -0
- data/lib/occi/core/parsers/json/category.rb +113 -0
- data/lib/occi/core/parsers/json/entity.rb +156 -0
- data/lib/occi/core/parsers/json/validator/.gitkeep +0 -0
- data/lib/occi/core/parsers/json/validator/action-instance.json +3 -0
- data/lib/occi/core/parsers/json/validator/entity-collection.json +3 -0
- data/lib/occi/core/parsers/json/validator/link-collection.json +3 -0
- data/lib/occi/core/parsers/json/validator/link.json +3 -0
- data/lib/occi/core/parsers/json/validator/locations.json +3 -0
- data/lib/occi/core/parsers/json/validator/mixin-collection.json +3 -0
- data/lib/occi/core/parsers/json/validator/model.json +3 -0
- data/lib/occi/core/parsers/json/validator/occi-schema.json +277 -0
- data/lib/occi/core/parsers/json/validator/resource-collection.json +3 -0
- data/lib/occi/core/parsers/json/validator/resource.json +3 -0
- data/lib/occi/core/parsers/json/validator.rb +87 -0
- data/lib/occi/core/parsers/json_parser.rb +128 -0
- data/lib/occi/core/parsers/text/.gitkeep +0 -0
- data/lib/occi/core/parsers/text/category.rb +183 -0
- data/lib/occi/core/parsers/text/constants.rb +89 -0
- data/lib/occi/core/parsers/text/entity.rb +257 -0
- data/lib/occi/core/parsers/text/location.rb +48 -0
- data/lib/occi/core/parsers/text_parser.rb +257 -0
- data/lib/occi/core/parsers.rb +18 -0
- data/lib/occi/core/renderer_factory.rb +213 -0
- data/lib/occi/core/renderers/.gitkeep +0 -0
- data/lib/occi/core/renderers/base_renderer.rb +81 -0
- data/lib/occi/core/renderers/json/.gitkeep +0 -0
- data/lib/occi/core/renderers/json/action_instance.rb +24 -0
- data/lib/occi/core/renderers/json/attributes.rb +50 -0
- data/lib/occi/core/renderers/json/base.rb +46 -0
- data/lib/occi/core/renderers/json/category.rb +85 -0
- data/lib/occi/core/renderers/json/collection.rb +52 -0
- data/lib/occi/core/renderers/json/instance.rb +39 -0
- data/lib/occi/core/renderers/json/link.rb +48 -0
- data/lib/occi/core/renderers/json/model.rb +26 -0
- data/lib/occi/core/renderers/json/resource.rb +27 -0
- data/lib/occi/core/renderers/json_renderer.rb +72 -0
- data/lib/occi/core/renderers/text/.gitkeep +0 -0
- data/lib/occi/core/renderers/text/action_instance.rb +36 -0
- data/lib/occi/core/renderers/text/attributes.rb +87 -0
- data/lib/occi/core/renderers/text/base.rb +82 -0
- data/lib/occi/core/renderers/text/category.rb +183 -0
- data/lib/occi/core/renderers/text/collection.rb +65 -0
- data/lib/occi/core/renderers/text/instance.rb +44 -0
- data/lib/occi/core/renderers/text/link.rb +40 -0
- data/lib/occi/core/renderers/text/model.rb +41 -0
- data/lib/occi/core/renderers/text/resource.rb +109 -0
- data/lib/occi/core/renderers/text_renderer.rb +72 -0
- data/lib/occi/core/renderers.rb +20 -0
- data/lib/occi/core/resource.rb +93 -57
- data/lib/occi/core/utils/.gitkeep +0 -0
- data/lib/occi/core/version.rb +17 -0
- data/lib/occi/core/warehouse/actions/.gitkeep +0 -0
- data/lib/occi/core/warehouse/actions/attributes/.gitkeep +0 -0
- data/lib/occi/core/warehouse/kinds/.gitkeep +0 -0
- data/lib/occi/core/warehouse/kinds/attributes/.gitkeep +0 -0
- data/lib/occi/core/warehouse/kinds/attributes/occi.core.id.yml +7 -0
- data/lib/occi/core/warehouse/kinds/attributes/occi.core.source.yml +7 -0
- data/lib/occi/core/warehouse/kinds/attributes/occi.core.summary.yml +7 -0
- data/lib/occi/core/warehouse/kinds/attributes/occi.core.target.yml +7 -0
- data/lib/occi/core/warehouse/kinds/attributes/occi.core.title.yml +7 -0
- data/lib/occi/core/warehouse/kinds/entity.yml +10 -0
- data/lib/occi/core/warehouse/kinds/link.yml +10 -0
- data/lib/occi/core/warehouse/kinds/resource.yml +9 -0
- data/lib/occi/core/warehouse/mixins/.gitkeep +0 -0
- data/lib/occi/core/warehouse/mixins/attributes/.gitkeep +0 -0
- data/lib/occi/core/warehouse.rb +115 -0
- data/lib/occi/core.rb +59 -23
- data/lib/occi/infrastructure/compute.rb +5 -122
- data/lib/occi/infrastructure/constants.rb +25 -0
- data/lib/occi/infrastructure/instance_builder.rb +24 -0
- data/lib/occi/infrastructure/mixins/.gitkeep +0 -0
- data/lib/occi/infrastructure/mixins/os_tpl.rb +19 -0
- data/lib/occi/infrastructure/mixins/resource_tpl.rb +19 -0
- data/lib/occi/infrastructure/mixins.rb +12 -0
- data/lib/occi/infrastructure/model.rb +27 -0
- data/lib/occi/infrastructure/network.rb +5 -104
- data/lib/occi/infrastructure/networkinterface.rb +5 -100
- data/lib/occi/infrastructure/storage.rb +5 -59
- data/lib/occi/infrastructure/storagelink.rb +5 -54
- data/lib/occi/infrastructure/version.rb +5 -0
- data/lib/occi/infrastructure/warehouse/actions/.gitkeep +0 -0
- data/lib/occi/infrastructure/warehouse/actions/attributes/.gitkeep +0 -0
- data/lib/occi/infrastructure/warehouse/actions/compute_restart.yml +12 -0
- data/lib/occi/infrastructure/warehouse/actions/compute_save.yml +19 -0
- data/lib/occi/infrastructure/warehouse/actions/compute_start.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/compute_stop.yml +12 -0
- data/lib/occi/infrastructure/warehouse/actions/compute_suspend.yml +12 -0
- data/lib/occi/infrastructure/warehouse/actions/network_down.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/network_up.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/networkinterface_down.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/networkinterface_up.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/storage_backup.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/storage_offline.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/storage_online.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/storage_resize.yml +12 -0
- data/lib/occi/infrastructure/warehouse/actions/storage_snapshot.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/storagelink_offline.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/storagelink_online.yml +4 -0
- data/lib/occi/infrastructure/warehouse/kinds/.gitkeep +0 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/.gitkeep +0 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.architecture.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.cores.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.hostname.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.memory.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.speed.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.state.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.network.label.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.network.state.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.network.vlan.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.networkinterface.interface.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.networkinterface.mac.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.networkinterface.state.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storage.size.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storage.state.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storagelink.deviceid.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storagelink.mountpoint.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storagelink.state.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/compute.yml +19 -0
- data/lib/occi/infrastructure/warehouse/kinds/network.yml +13 -0
- data/lib/occi/infrastructure/warehouse/kinds/networkinterface.yml +13 -0
- data/lib/occi/infrastructure/warehouse/kinds/storage.yml +15 -0
- data/lib/occi/infrastructure/warehouse/kinds/storagelink.yml +13 -0
- data/lib/occi/infrastructure/warehouse/mixins/.gitkeep +0 -0
- data/lib/occi/infrastructure/warehouse/mixins/attributes/.gitkeep +0 -0
- data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.network.address.yml +7 -0
- data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.network.allocation.yml +7 -0
- data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.network.gateway.yml +7 -0
- data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.networkinterface.address.yml +7 -0
- data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.networkinterface.allocation.yml +7 -0
- data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.networkinterface.gateway.yml +7 -0
- data/lib/occi/infrastructure/warehouse/mixins/ipnetwork.yml +11 -0
- data/lib/occi/infrastructure/warehouse/mixins/ipnetworkinterface.yml +11 -0
- data/lib/occi/infrastructure/warehouse.rb +20 -0
- data/lib/occi/infrastructure-ext.rb +35 -0
- data/lib/occi/infrastructure.rb +34 -19
- data/lib/occi/infrastructure_ext/constants.rb +20 -0
- data/lib/occi/infrastructure_ext/instance_builder.rb +22 -0
- data/lib/occi/infrastructure_ext/ipreservation.rb +9 -0
- data/lib/occi/infrastructure_ext/mixins/.gitkeep +0 -0
- data/lib/occi/infrastructure_ext/mixins/availability_zone.rb +19 -0
- data/lib/occi/infrastructure_ext/mixins.rb +12 -0
- data/lib/occi/infrastructure_ext/model.rb +26 -0
- data/lib/occi/infrastructure_ext/securitygroup.rb +9 -0
- data/lib/occi/infrastructure_ext/securitygrouplink.rb +9 -0
- data/lib/occi/infrastructure_ext/version.rb +5 -0
- data/lib/occi/infrastructure_ext/warehouse/actions/.gitkeep +0 -0
- data/lib/occi/infrastructure_ext/warehouse/actions/attributes/.gitkeep +0 -0
- data/lib/occi/infrastructure_ext/warehouse/actions/ipreservation_down.yml +4 -0
- data/lib/occi/infrastructure_ext/warehouse/actions/ipreservation_up.yml +4 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/.gitkeep +0 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/.gitkeep +0 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.ipreservation.address.yml +7 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.ipreservation.state.yml +7 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.ipreservation.used.yml +7 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.securitygroup.rules.yml +7 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.securitygroup.state.yml +7 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.securitygrouplink.state.yml +7 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/ipreservation.yml +13 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/securitygroup.yml +9 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/securitygrouplink.yml +8 -0
- data/lib/occi/infrastructure_ext/warehouse/mixins/.gitkeep +0 -0
- data/lib/occi/infrastructure_ext/warehouse/mixins/attributes/.gitkeep +0 -0
- data/lib/occi/infrastructure_ext/warehouse.rb +20 -0
- data/lib/occi/monkey_island/boolean.rb +6 -0
- data/lib/occi/monkey_island/hash.rb +4 -0
- data/occi-core.gemspec +26 -26
- metadata +312 -243
- data/.yardopts +0 -1
- data/config/occi.yml +0 -4
- data/lib/occi/collection.rb +0 -265
- data/lib/occi/core/actions.rb +0 -21
- data/lib/occi/core/attributes.rb +0 -411
- data/lib/occi/core/categories.rb +0 -64
- data/lib/occi/core/dependencies.rb +0 -7
- data/lib/occi/core/entities.rb +0 -48
- data/lib/occi/core/kinds.rb +0 -22
- data/lib/occi/core/links.rb +0 -37
- data/lib/occi/core/mixins.rb +0 -37
- data/lib/occi/core/properties.rb +0 -108
- data/lib/occi/core/resources.rb +0 -14
- data/lib/occi/errors/attribute_definitions_converted_error.rb +0 -5
- data/lib/occi/errors/attribute_missing_error.rb +0 -5
- data/lib/occi/errors/attribute_name_invalid_error.rb +0 -5
- data/lib/occi/errors/attribute_not_defined_error.rb +0 -5
- data/lib/occi/errors/attribute_property_type_error.rb +0 -5
- data/lib/occi/errors/attribute_type_error.rb +0 -5
- data/lib/occi/errors/category_not_defined_error.rb +0 -5
- data/lib/occi/errors/kind_not_defined_error.rb +0 -5
- data/lib/occi/errors/parser_input_error.rb +0 -5
- data/lib/occi/errors/parser_type_error.rb +0 -5
- data/lib/occi/errors.rb +0 -1
- data/lib/occi/extensions/hashie.rb +0 -25
- data/lib/occi/helpers/comparators/action_instance.rb +0 -22
- data/lib/occi/helpers/comparators/attributes.rb +0 -22
- data/lib/occi/helpers/comparators/categories.rb +0 -22
- data/lib/occi/helpers/comparators/category.rb +0 -22
- data/lib/occi/helpers/comparators/collection.rb +0 -40
- data/lib/occi/helpers/comparators/entities.rb +0 -22
- data/lib/occi/helpers/comparators/entity.rb +0 -22
- data/lib/occi/helpers/comparators/properties.rb +0 -26
- data/lib/occi/helpers/comparators.rb +0 -1
- data/lib/occi/helpers/inspect.rb +0 -12
- data/lib/occi/infrastructure/network/ipnetwork.rb +0 -28
- data/lib/occi/infrastructure/networkinterface/ipnetworkinterface.rb +0 -28
- data/lib/occi/infrastructure/os_tpl.rb +0 -20
- data/lib/occi/infrastructure/resource_tpl.rb +0 -20
- data/lib/occi/log.rb +0 -71
- data/lib/occi/model.rb +0 -87
- data/lib/occi/parser/json.rb +0 -38
- data/lib/occi/parser/text/constants.rb +0 -89
- data/lib/occi/parser/text.rb +0 -280
- data/lib/occi/parser.rb +0 -144
- data/lib/occi/settings.rb +0 -10
- data/lib/occi/version.rb +0 -3
- data/lib/occi-core.rb +0 -53
- data/spec/helpers/to_plain.rb +0 -39
- data/spec/helpers/yaml_hash.rb +0 -32
- data/spec/occi/collection_samples/collection1.json +0 -1
- data/spec/occi/collection_samples/directory2/collection2.json +0 -1
- data/spec/occi/collection_spec.rb +0 -1003
- data/spec/occi/core/action_instance_spec.rb +0 -317
- data/spec/occi/core/action_spec.rb +0 -71
- data/spec/occi/core/attributes_spec.rb +0 -665
- data/spec/occi/core/categories_spec.rb +0 -28
- data/spec/occi/core/category_spec.rb +0 -216
- data/spec/occi/core/entities_spec.rb +0 -160
- data/spec/occi/core/entity_spec.rb +0 -374
- data/spec/occi/core/kind_spec.rb +0 -182
- data/spec/occi/core/link_spec.rb +0 -52
- data/spec/occi/core/links_spec.rb +0 -132
- data/spec/occi/core/mixin_spec.rb +0 -38
- data/spec/occi/core/mixins_spec.rb +0 -107
- data/spec/occi/core/properties_spec.rb +0 -171
- data/spec/occi/core/resource_spec.rb +0 -42
- data/spec/occi/core_spec.rb +0 -12
- data/spec/occi/infrastructure/compute_spec.rb +0 -229
- data/spec/occi/infrastructure/network_spec.rb +0 -96
- data/spec/occi/infrastructure/networkinterface_spec.rb +0 -96
- data/spec/occi/infrastructure/storage_spec.rb +0 -33
- data/spec/occi/infrastructure/storagelink_spec.rb +0 -45
- data/spec/occi/log_spec.rb +0 -117
- data/spec/occi/model_spec.rb +0 -256
- data/spec/occi/parser/json_samples/test.json +0 -49
- data/spec/occi/parser/text_samples/occi_categories.body_plain.expected +0 -2
- data/spec/occi/parser/text_samples/occi_categories.expected +0 -2
- data/spec/occi/parser/text_samples/occi_categories.parse_headers.expected +0 -2
- data/spec/occi/parser/text_samples/occi_categories.text +0 -2
- data/spec/occi/parser/text_samples/occi_compute_rocci_server.expected +0 -11
- data/spec/occi/parser/text_samples/occi_compute_rocci_server.text +0 -10
- data/spec/occi/parser/text_samples/occi_link_resource_instance.body_plain.expected +0 -7
- data/spec/occi/parser/text_samples/occi_link_resource_instance.expected +0 -7
- data/spec/occi/parser/text_samples/occi_link_resource_instance.parse.expected +0 -7
- data/spec/occi/parser/text_samples/occi_link_resource_instance.text +0 -7
- data/spec/occi/parser/text_samples/occi_link_simple.expected +0 -7
- data/spec/occi/parser/text_samples/occi_link_simple.text +0 -1
- data/spec/occi/parser/text_samples/occi_link_w_attributes.expected +0 -7
- data/spec/occi/parser/text_samples/occi_link_w_attributes.text +0 -7
- data/spec/occi/parser/text_samples/occi_link_w_category.expected +0 -7
- data/spec/occi/parser/text_samples/occi_link_w_category.text +0 -3
- data/spec/occi/parser/text_samples/occi_model_categories.expected +0 -3
- data/spec/occi/parser/text_samples/occi_model_rocci_server.text +0 -51
- data/spec/occi/parser/text_samples/occi_network_rocci_server.body_plain.expected +0 -11
- data/spec/occi/parser/text_samples/occi_network_rocci_server.expected +0 -11
- data/spec/occi/parser/text_samples/occi_network_rocci_server.resource.header.expected +0 -9
- data/spec/occi/parser/text_samples/occi_network_rocci_server.resource.rack.expected +0 -9
- data/spec/occi/parser/text_samples/occi_network_rocci_server.text +0 -11
- data/spec/occi/parser/text_samples/occi_resource_custom_class_w_attributes.parse.expected +0 -15
- data/spec/occi/parser/text_samples/occi_resource_custom_class_w_attributes.text +0 -15
- data/spec/occi/parser/text_samples/occi_resource_w_attributes.text +0 -11
- data/spec/occi/parser/text_samples/occi_resource_w_inline_links.expected +0 -1
- data/spec/occi/parser/text_samples/occi_resource_w_inline_links.text +0 -16
- data/spec/occi/parser/text_samples/occi_resource_w_inline_links_only.text +0 -13
- data/spec/occi/parser/text_samples/occi_storage_rocci_server.expected +0 -9
- data/spec/occi/parser/text_samples/occi_storage_rocci_server.text +0 -9
- data/spec/occi/parser/text_spec.rb +0 -320
- data/spec/occi/parser_spec.rb +0 -259
- data/spec/occi-core_spec.rb +0 -31
- data/spec/spec_helper.rb +0 -18
@@ -0,0 +1,269 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
# Contains an attribute definition information.
|
4
|
+
# This definition does not carry the name of the
|
5
|
+
# attribute or its value. These should be associated
|
6
|
+
# with the definition by other means, e.g. in a hash
|
7
|
+
# `{ name: definition }` or by using instances of
|
8
|
+
# the `Occi::Core::Attribute` class.
|
9
|
+
#
|
10
|
+
# @attr type [Class] Ruby class of the desired value
|
11
|
+
# @attr required [TrueClass, FalseClass] required flag
|
12
|
+
# @attr mutable [TrueClass, FalseClass] mutable flag
|
13
|
+
# @attr default [Object] default value, optional
|
14
|
+
# @attr description [String, NilClass] attribute description, optional
|
15
|
+
# @attr pattern [Regexp, NilClass] value pattern, only for type `String`
|
16
|
+
#
|
17
|
+
# @author Boris Parak <parak@cesnet.cz>
|
18
|
+
class AttributeDefinition
|
19
|
+
include Yell::Loggable
|
20
|
+
include Helpers::ArgumentValidator
|
21
|
+
extend Helpers::YamlSummoner
|
22
|
+
|
23
|
+
attr_accessor :type, :required, :mutable,
|
24
|
+
:default, :description, :pattern
|
25
|
+
|
26
|
+
# Constructs an instance with sensible defaults. The default
|
27
|
+
# definition is for a String-based optional attribute without
|
28
|
+
# a pattern.
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
# AttributeDefinition.new type: Integer, required: true
|
32
|
+
# AttributeDefinition.new
|
33
|
+
#
|
34
|
+
# @param args [Hash] arguments with definition information
|
35
|
+
# @option args [Class] :type (String) class of the desired value
|
36
|
+
# @option args [TrueClass, FalseClass] :required (false) required flag
|
37
|
+
# @option args [TrueClass, FalseClass] :mutable (true) mutable flag
|
38
|
+
# @option args [Object] :default (nil) default value
|
39
|
+
# @option args [String, NilClass] :description (nil) attribute description
|
40
|
+
# @option args [Regexp, NilClass] :pattern (nil) value pattern
|
41
|
+
def initialize(args = {})
|
42
|
+
default_args! args
|
43
|
+
|
44
|
+
@type = args.fetch(:type)
|
45
|
+
@required = args.fetch(:required)
|
46
|
+
@mutable = args.fetch(:mutable)
|
47
|
+
@default = args.fetch(:default)
|
48
|
+
@description = args.fetch(:description)
|
49
|
+
@pattern = args.fetch(:pattern)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Alias with a question mark
|
53
|
+
alias required? required
|
54
|
+
alias mutable? mutable
|
55
|
+
|
56
|
+
# Changes the value of `required` to `true`, in case
|
57
|
+
# `required` is `nil` or `false`.
|
58
|
+
#
|
59
|
+
# @example
|
60
|
+
# attr_def.required? # => false
|
61
|
+
# attr_def.required!
|
62
|
+
# attr_def.required? # => true
|
63
|
+
def required!
|
64
|
+
self.required = true
|
65
|
+
end
|
66
|
+
|
67
|
+
# Shorthand for getting the negated value of `required`.
|
68
|
+
#
|
69
|
+
# @example
|
70
|
+
# attr_def.required? # => false
|
71
|
+
# attr_def.optional? # => true
|
72
|
+
#
|
73
|
+
# @return [TrueClass, FalseClass] negated value of `required`
|
74
|
+
def optional?
|
75
|
+
!required?
|
76
|
+
end
|
77
|
+
|
78
|
+
# Changes the value of `required` to `false`, in case
|
79
|
+
# `required` is `nil` or `true`.
|
80
|
+
#
|
81
|
+
# @example
|
82
|
+
# attr_def.required? # => true
|
83
|
+
# attr_def.optional!
|
84
|
+
# attr_def.required? # => false
|
85
|
+
def optional!
|
86
|
+
self.required = false
|
87
|
+
end
|
88
|
+
|
89
|
+
# Changes the value of `mutable` to `true`, in case
|
90
|
+
# `mutable` is `nil` or `false`.
|
91
|
+
#
|
92
|
+
# @example
|
93
|
+
# attr_def.mutable? # => false
|
94
|
+
# attr_def.mutable!
|
95
|
+
# attr_def.mutable? # => true
|
96
|
+
def mutable!
|
97
|
+
self.mutable = true
|
98
|
+
end
|
99
|
+
|
100
|
+
# Shorthand for getting the negated value of `mutable`.
|
101
|
+
#
|
102
|
+
# @example
|
103
|
+
# attr_def.mutable? # => true
|
104
|
+
# attr_def.immutable? # => false
|
105
|
+
#
|
106
|
+
# @return [TrueClass, FalseClass] negated value of `mutable`
|
107
|
+
def immutable?
|
108
|
+
!mutable?
|
109
|
+
end
|
110
|
+
|
111
|
+
# Changes the value of `mutable` to `false`, in case
|
112
|
+
# `mutable` is `nil` or `true`.
|
113
|
+
#
|
114
|
+
# @example
|
115
|
+
# attr_def.mutable? # => true
|
116
|
+
# attr_def.immutable!
|
117
|
+
# attr_def.mutable? # => false
|
118
|
+
def immutable!
|
119
|
+
self.mutable = false
|
120
|
+
end
|
121
|
+
|
122
|
+
# Indicates the presence of a default value.
|
123
|
+
#
|
124
|
+
# @example
|
125
|
+
# attr_def.default # => nil
|
126
|
+
# attr_def.default? # => false
|
127
|
+
#
|
128
|
+
# @return [TrueClass, FalseClass] default value indicator
|
129
|
+
def default?
|
130
|
+
!default.nil?
|
131
|
+
end
|
132
|
+
|
133
|
+
# Indicates the presence of a pattern for value.
|
134
|
+
#
|
135
|
+
# @example
|
136
|
+
# attr_def.pattern # => /.*/
|
137
|
+
# attr_def.pattern? # => true
|
138
|
+
#
|
139
|
+
# @return [TrueClass, FalseClass] pattern indicator
|
140
|
+
def pattern?
|
141
|
+
!pattern.nil?
|
142
|
+
end
|
143
|
+
|
144
|
+
# Indicates whether the given value is an acceptable
|
145
|
+
# value for an attribute with this definition.
|
146
|
+
#
|
147
|
+
# @example
|
148
|
+
# attr_def.type # => String
|
149
|
+
# attr_def.value? 5.0 # => false
|
150
|
+
#
|
151
|
+
# @param value [Object] candidate value
|
152
|
+
# @return [TrueClass, FalseClass] validation result
|
153
|
+
def valid?(value)
|
154
|
+
begin
|
155
|
+
valid! value
|
156
|
+
rescue Occi::Core::Errors::AttributeValidationError => ex
|
157
|
+
logger.debug "AttributeValidation: #{ex.message}"
|
158
|
+
return false
|
159
|
+
end
|
160
|
+
|
161
|
+
true
|
162
|
+
end
|
163
|
+
|
164
|
+
# Indicates whether the given value is an acceptable
|
165
|
+
# value for an attribute with this definition. This
|
166
|
+
# method will raise an error if the given value is
|
167
|
+
# not acceptable.
|
168
|
+
#
|
169
|
+
# @example
|
170
|
+
# attr_def.type # => String
|
171
|
+
# attr_def.value! 0.5 # => Occi::Core::Errors::AttributeValidationError
|
172
|
+
#
|
173
|
+
# @param value [Object] candidate value
|
174
|
+
def valid!(value)
|
175
|
+
valid_type!
|
176
|
+
valid_value! value
|
177
|
+
end
|
178
|
+
|
179
|
+
private
|
180
|
+
|
181
|
+
# :nodoc:
|
182
|
+
def valid_type!
|
183
|
+
return if type
|
184
|
+
raise Occi::Core::Errors::AttributeValidationError,
|
185
|
+
'No type has been defined'
|
186
|
+
end
|
187
|
+
|
188
|
+
# :nodoc:
|
189
|
+
def valid_value!(value)
|
190
|
+
if value.nil? && required?
|
191
|
+
raise Occi::Core::Errors::AttributeValidationError,
|
192
|
+
'Value is required but not provided'
|
193
|
+
end
|
194
|
+
return if value.nil? && optional?
|
195
|
+
|
196
|
+
unless value_ancestors(value).include?(type)
|
197
|
+
raise Occi::Core::Errors::AttributeValidationError,
|
198
|
+
"Type #{value.class} is incompatible with " \
|
199
|
+
"defined type #{type}"
|
200
|
+
end
|
201
|
+
|
202
|
+
match_pattern! value
|
203
|
+
end
|
204
|
+
|
205
|
+
# :nodoc:
|
206
|
+
def match_pattern!(value)
|
207
|
+
return unless type_ancestors.include?(String)
|
208
|
+
return unless pattern?
|
209
|
+
return if pattern.match(value)
|
210
|
+
|
211
|
+
raise Occi::Core::Errors::AttributeValidationError,
|
212
|
+
"#{value.inspect} does not match pattern #{pattern.inspect}"
|
213
|
+
end
|
214
|
+
|
215
|
+
# :nodoc:
|
216
|
+
def type_ancestors
|
217
|
+
type.ancestors
|
218
|
+
end
|
219
|
+
|
220
|
+
# :nodoc:
|
221
|
+
def value_ancestors(value)
|
222
|
+
value.class.ancestors
|
223
|
+
end
|
224
|
+
|
225
|
+
# :nodoc:
|
226
|
+
def sufficient_args!(args)
|
227
|
+
sufficient_type! args[:type]
|
228
|
+
|
229
|
+
%i[required mutable].each do |attr|
|
230
|
+
next unless args[attr].nil?
|
231
|
+
raise Occi::Core::Errors::MandatoryArgumentError,
|
232
|
+
"#{attr} is a mandatory argument"
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
# :nodoc:
|
237
|
+
def sufficient_type!(type)
|
238
|
+
if type.nil?
|
239
|
+
raise Occi::Core::Errors::MandatoryArgumentError,
|
240
|
+
'type is a mandatory argument'
|
241
|
+
end
|
242
|
+
|
243
|
+
return if type.is_a?(Class) || type.is_a?(Module)
|
244
|
+
raise Occi::Core::Errors::MandatoryArgumentError,
|
245
|
+
'type must be a class or module'
|
246
|
+
end
|
247
|
+
|
248
|
+
# :nodoc:
|
249
|
+
def defaults
|
250
|
+
{
|
251
|
+
type: String,
|
252
|
+
required: false,
|
253
|
+
mutable: true,
|
254
|
+
default: nil,
|
255
|
+
description: nil,
|
256
|
+
pattern: nil
|
257
|
+
}
|
258
|
+
end
|
259
|
+
|
260
|
+
class << self
|
261
|
+
# :nodoc:
|
262
|
+
def allowed_yaml_classes
|
263
|
+
[String, Regexp, URI, IPAddr, Integer, Float, Boolean, Array, Hash].freeze
|
264
|
+
end
|
265
|
+
private :allowed_yaml_classes
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
data/lib/occi/core/category.rb
CHANGED
@@ -1,111 +1,138 @@
|
|
1
1
|
module Occi
|
2
2
|
module Core
|
3
|
+
# Implements the base class for all OCCI categories, including
|
4
|
+
# `Kind`, `Action`, and `Mixin`.
|
5
|
+
#
|
6
|
+
# @attr term [String] category term
|
7
|
+
# @attr schema [String] category schema, ending with '#'
|
8
|
+
# @attr title [String] category title
|
9
|
+
# @attr attributes [Hash] category attributes
|
10
|
+
#
|
11
|
+
# @attr_reader identifier [String] full identifier constructed from term and schema
|
12
|
+
#
|
13
|
+
# @abstract The base class itself is not renderable and should be
|
14
|
+
# used as an abstract starting point.
|
15
|
+
# @author Boris Parak <parak@cesnet.cz>
|
3
16
|
class Category
|
4
|
-
|
5
|
-
include
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
17
|
+
include Yell::Loggable
|
18
|
+
include Helpers::Renderable
|
19
|
+
extend Helpers::IdentifierValidator
|
20
|
+
include Helpers::AttributesAccessor
|
21
|
+
include Helpers::ArgumentValidator
|
22
|
+
extend Helpers::YamlSummoner
|
23
|
+
|
24
|
+
attr_accessor :term, :schema, :title, :attributes
|
25
|
+
|
26
|
+
# Constructs an instance with the given category information.
|
27
|
+
# Both `term` and `schema` are mandatory arguments. `schema` must
|
28
|
+
# be terminated with '#'.
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
# Category.new term: 'gnr', schema: 'http://example.org/test#'
|
32
|
+
#
|
33
|
+
# @param args [Hash] arguments with category information
|
34
|
+
# @option args [String] :term category term
|
35
|
+
# @option args [String] :schema category schema, ending with '#'
|
36
|
+
# @option args [String] :title (nil) category title
|
37
|
+
# @option args [Hash] :attributes (Hash) category attributes
|
38
|
+
def initialize(args = {})
|
39
|
+
pre_initialize(args)
|
40
|
+
default_args! args
|
41
|
+
|
42
|
+
@term = args.fetch(:term)
|
43
|
+
@schema = args.fetch(:schema)
|
44
|
+
@title = args.fetch(:title)
|
45
|
+
@attributes = args.fetch(:attributes)
|
46
|
+
|
47
|
+
post_initialize(args)
|
32
48
|
end
|
33
49
|
|
34
|
-
#
|
35
|
-
|
36
|
-
|
50
|
+
# Returns a full category identifier constructed from
|
51
|
+
# `term` and `schema`.
|
52
|
+
#
|
53
|
+
# @example
|
54
|
+
# category.identifier # => 'http://example.org/test#gnr'
|
55
|
+
#
|
56
|
+
# @return [String] category identifier
|
57
|
+
def identifier
|
58
|
+
"#{schema}#{term}"
|
37
59
|
end
|
38
60
|
|
39
|
-
#
|
40
|
-
#
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
61
|
+
# Performs internal validation of the category. Returns
|
62
|
+
# `true` or `false` depending on the result. Currently, only
|
63
|
+
# the category identifier is used in this process.
|
64
|
+
#
|
65
|
+
# @example
|
66
|
+
# category.valid? # => true
|
67
|
+
#
|
68
|
+
# @return [TrueClass] when valid
|
69
|
+
# @return [FalseClass] when invalid
|
70
|
+
def valid?
|
71
|
+
# TODO: validate attribute definitions?
|
72
|
+
self.class.valid_identifier? identifier
|
48
73
|
end
|
49
74
|
|
50
|
-
#
|
51
|
-
|
52
|
-
|
75
|
+
# Performs internal validation of the category. Raises error
|
76
|
+
# depending on the result. Currently, only the category
|
77
|
+
# identifier is used in this process.
|
78
|
+
#
|
79
|
+
# @example
|
80
|
+
# category.valid!
|
81
|
+
#
|
82
|
+
# @raise [Occi::Core::Errors::CategoryValidationError] when invalid
|
83
|
+
def valid!
|
84
|
+
# TODO: validate attribute definitions?
|
85
|
+
self.class.valid_identifier! identifier
|
53
86
|
end
|
54
87
|
|
55
|
-
#
|
56
|
-
def
|
57
|
-
|
58
|
-
string << ";title=#{self.title.inspect}" if self.title
|
59
|
-
string
|
88
|
+
# :nodoc:
|
89
|
+
def to_s
|
90
|
+
identifier
|
60
91
|
end
|
61
92
|
|
62
|
-
#
|
63
|
-
def
|
64
|
-
|
93
|
+
# :nodoc:
|
94
|
+
def ==(other)
|
95
|
+
return false unless other && other.respond_to?(:identifier)
|
96
|
+
identifier == other.identifier
|
65
97
|
end
|
66
98
|
|
67
|
-
#
|
68
|
-
def
|
69
|
-
|
99
|
+
# :nodoc:
|
100
|
+
def eql?(other)
|
101
|
+
self == other
|
70
102
|
end
|
71
103
|
|
72
|
-
#
|
73
|
-
def
|
74
|
-
|
104
|
+
# :nodoc:
|
105
|
+
def hash
|
106
|
+
identifier.hash
|
75
107
|
end
|
76
108
|
|
77
|
-
|
78
|
-
def to_s
|
79
|
-
self.type_identifier
|
80
|
-
end
|
109
|
+
protected
|
81
110
|
|
82
|
-
#
|
83
|
-
def
|
84
|
-
term.
|
111
|
+
# :nodoc:
|
112
|
+
def sufficient_args!(args)
|
113
|
+
%i[term schema].each do |attr|
|
114
|
+
unless self.class.send("valid_#{attr}?", args[attr])
|
115
|
+
raise Occi::Core::Errors::MandatoryArgumentError, "#{attr} is a mandatory " \
|
116
|
+
"argument for #{self.class}"
|
117
|
+
end
|
118
|
+
end
|
85
119
|
end
|
86
120
|
|
87
|
-
#
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
raise Occi::Errors::CategoryNotDefinedError,
|
96
|
-
"Category #{self.class.name}[#{type_identifier.inspect}] not found in the model!" unless cat
|
97
|
-
|
98
|
-
# TODO: impl. check_attributes and check_title for strict matching
|
99
|
-
|
100
|
-
true
|
121
|
+
# :nodoc:
|
122
|
+
def defaults
|
123
|
+
{
|
124
|
+
term: nil,
|
125
|
+
schema: nil,
|
126
|
+
title: nil,
|
127
|
+
attributes: {}
|
128
|
+
}
|
101
129
|
end
|
102
130
|
|
103
|
-
#
|
104
|
-
|
105
|
-
def self.valid_term?(term)
|
106
|
-
term =~ /^[a-z][a-z0-9_-]*$/
|
107
|
-
end
|
131
|
+
# :nodoc:
|
132
|
+
def pre_initialize(args); end
|
108
133
|
|
134
|
+
# :nodoc:
|
135
|
+
def post_initialize(args); end
|
109
136
|
end
|
110
137
|
end
|
111
138
|
end
|