occi-core 5.0.0.beta.3 → 5.0.0.beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ff25ef95f7d16fdf2db6c9d7cfb6603eec65d74
4
- data.tar.gz: 58b65c4f48697fa1325172876d66e7fa93602f72
3
+ metadata.gz: e2e1b39411baa08d88b06220dc9478fed8dc9853
4
+ data.tar.gz: 38abfa1554fd73fb0107be365060cc8858ff3eb6
5
5
  SHA512:
6
- metadata.gz: a4529b0f62d7b9dfb8884e4bbc9fa53ea08679c8f71b3abd0359a58f0bbea64163eb1829dedb65092589117d48710f81483a8c08435d06535bd18a14a2137693
7
- data.tar.gz: 3913ef638ad8dabd8ea4739ea2e561292fa5356075110e3f373ec3808acd34386b82d2ea5a4d47b15b5e5d5e0a6b1bf28204f182ca127aef0acd3b2959edd430
6
+ metadata.gz: 308dac6e39d40ba9df868b98f5e02ec2eab4e5242b6f48cc688d124c3b221654e91d6a48f80a906a8700acd397fb09f9094f29d45ca071cf333c30c9b4da6654
7
+ data.tar.gz: c0ef2b4f0c161a672aece4f5d5596463e3ff562967967d9bc8c0bc44d050b678ceec03563b7a6090a44a327170c5515ae4c953642c6022a072b79c2d5f8c8a4e
@@ -55,6 +55,7 @@ module Occi
55
55
  autoload :Model, 'occi/core/model'
56
56
  autoload :Warehouse, 'occi/core/warehouse'
57
57
  autoload :InstanceBuilder, 'occi/core/instance_builder'
58
+ autoload :Locations, 'occi/core/locations'
58
59
  end
59
60
  end
60
61
 
@@ -0,0 +1,13 @@
1
+ require 'occi/core/errors/validation_error'
2
+
3
+ module Occi
4
+ module Core
5
+ module Errors
6
+ # Custom error class indicating validation failures on
7
+ # various Core class instances.
8
+ #
9
+ # @author Boris Parak <parak@cesnet.cz>
10
+ class LocationValidationError < ValidationError; end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,109 @@
1
+ module Occi
2
+ module Core
3
+ # Implments handling helpers for OCCI locations. These are especially useful for rendering
4
+ # and butter-passing purposes.
5
+ #
6
+ # @attr uris [Set] collection of URIs representing locations
7
+ #
8
+ # @author Boris Parak <parak@cesnet.cz>
9
+ class Locations
10
+ include Yell::Loggable
11
+ include Helpers::Renderable
12
+ include Helpers::ArgumentValidator
13
+ include Enumerable
14
+
15
+ # Methods to be redirected to `uris`
16
+ ENUM_METHODS = %i[each << add remove map! empty? include?].freeze
17
+ delegate(*ENUM_METHODS, to: :uris)
18
+
19
+ attr_accessor :uris
20
+
21
+ # Constructs an instance with given URIs. If `uris` are omitted, an empty
22
+ # set will be automatically provided.
23
+ #
24
+ # @param args [Hash] arguments with Location information
25
+ # @option args [Set] :uris collection of URIs representing locations
26
+ def initialize(args = {})
27
+ pre_initialize(args)
28
+ default_args! args
29
+
30
+ @uris = args.fetch(:uris)
31
+
32
+ post_initialize(args)
33
+ end
34
+
35
+ # Applies given `host` to all locations contained in the collection.
36
+ #
37
+ # @param host [String] hostname for locations
38
+ def host=(host)
39
+ each { |uri| uri.host = host }
40
+ end
41
+
42
+ # Applies given `port` to all locations contained in the collection.
43
+ #
44
+ # @param port [String] port number
45
+ def port=(port)
46
+ each { |uri| uri.port = port }
47
+ end
48
+
49
+ # Applies given `scheme` to all locations contained in the collection.
50
+ #
51
+ # @param scheme [String] URI scheme
52
+ def scheme=(scheme)
53
+ each { |uri| uri.scheme = scheme }
54
+ end
55
+
56
+ # Validates all locations contained in the collection. Validation
57
+ # errors are only logged.
58
+ #
59
+ # @return [TrueClass] if locations are valid
60
+ # @return [FalseClass] if locations are invalid
61
+ def valid?
62
+ valid!
63
+ true
64
+ rescue => ex
65
+ logger.warn "Location invalid: #{ex.message}"
66
+ false
67
+ end
68
+
69
+ # Validates all locations in the collections and raises an error
70
+ # if there is an invalid location. During this process, all locations
71
+ # will be converted to `URI` instances.
72
+ #
73
+ # @raise [Occi::Core::Errors::LocationValidationError] if some location is invalid
74
+ def valid!
75
+ map! { |uri| return_or_convert uri }
76
+ rescue => ex
77
+ raise Occi::Core::Errors::LocationValidationError, ex.message
78
+ end
79
+ alias convert! valid!
80
+
81
+ protected
82
+
83
+ # :nodoc:
84
+ def sufficient_args!(args)
85
+ return if args[:uris]
86
+ raise Occi::Core::Errors::MandatoryArgumentError, "'uris' is a mandatory argument for #{self.class}"
87
+ end
88
+
89
+ # :nodoc:
90
+ def defaults
91
+ { uris: Set.new }
92
+ end
93
+
94
+ # :nodoc:
95
+ def pre_initialize(args); end
96
+
97
+ # :nodoc:
98
+ def post_initialize(args); end
99
+
100
+ private
101
+
102
+ # :nodoc:
103
+ def return_or_convert(uri)
104
+ return uri if uri.is_a?(URI)
105
+ URI.parse uri
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,20 @@
1
+ require 'occi/core/renderers/json/base'
2
+
3
+ module Occi
4
+ module Core
5
+ module Renderers
6
+ module Json
7
+ # Implements routines required to render `Occi::Core::Locations` and
8
+ # its subclasses to a JSON-based representation.
9
+ #
10
+ # @author Boris Parak <parak@cesnet.cz>
11
+ class Locations < Base
12
+ # :nodoc:
13
+ def render_hash
14
+ object.map(&:to_s)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -62,7 +62,8 @@ module Occi
62
62
  'Occi::Core::Collection' => Occi::Core::Renderers::Json::Collection,
63
63
  'Occi::Core::Model' => Occi::Core::Renderers::Json::Model,
64
64
  'Occi::Core::Resource' => Occi::Core::Renderers::Json::Resource,
65
- 'Occi::Core::Link' => Occi::Core::Renderers::Json::Link
65
+ 'Occi::Core::Link' => Occi::Core::Renderers::Json::Link,
66
+ 'Occi::Core::Locations' => Occi::Core::Renderers::Json::Locations
66
67
  }
67
68
  end
68
69
  end
@@ -0,0 +1,38 @@
1
+ require 'occi/core/renderers/text/base'
2
+
3
+ module Occi
4
+ module Core
5
+ module Renderers
6
+ module Text
7
+ # Implements routines required to render `Occi::Core::Locations` and
8
+ # its subclasses to a text-based representation. Supports rendering
9
+ # to plain and header-like formats.
10
+ #
11
+ # @author Boris Parak <parak@cesnet.cz>
12
+ class Locations < Base
13
+ # Location key constants
14
+ LOCATION_KEY_PLAIN = 'X-OCCI-Location'.freeze
15
+ LOCATION_KEY_HEADERS = 'Location'.freeze
16
+
17
+ # Renders `object` into plain text and returns the result
18
+ # as `String`.
19
+ #
20
+ # @return [String] textual representation of Object
21
+ def render_plain
22
+ locs = object.map { |loc| "#{LOCATION_KEY_PLAIN}: #{loc}" }
23
+ locs.join "\n"
24
+ end
25
+
26
+ # Renders `object` into text for headers and returns the result
27
+ # as `Hash`.
28
+ #
29
+ # @return [Hash] textual representation of Object for headers
30
+ def render_headers
31
+ return {} if object.empty?
32
+ { LOCATION_KEY_HEADERS => object.map(&:to_s) }
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -62,7 +62,8 @@ module Occi
62
62
  'Occi::Core::Collection' => Occi::Core::Renderers::Text::Collection,
63
63
  'Occi::Core::Model' => Occi::Core::Renderers::Text::Model,
64
64
  'Occi::Core::Resource' => Occi::Core::Renderers::Text::Resource,
65
- 'Occi::Core::Link' => Occi::Core::Renderers::Text::Link
65
+ 'Occi::Core::Link' => Occi::Core::Renderers::Text::Link,
66
+ 'Occi::Core::Locations' => Occi::Core::Renderers::Text::Locations
66
67
  }
67
68
  end
68
69
  end
@@ -3,7 +3,7 @@ module Occi
3
3
  MAJOR_VERSION = 5 # Major update constant
4
4
  MINOR_VERSION = 0 # Minor update constant
5
5
  PATCH_VERSION = 0 # Patch/Fix version constant
6
- STAGE_VERSION = 'beta.3'.freeze # use `nil` for production releases
6
+ STAGE_VERSION = 'beta.4'.freeze # use `nil` for production releases
7
7
 
8
8
  unless defined?(::Occi::Core::VERSION)
9
9
  VERSION = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: occi-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.beta.3
4
+ version: 5.0.0.beta.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Parak
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-06-22 00:00:00.000000000 Z
13
+ date: 2017-07-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -353,6 +353,7 @@ files:
353
353
  - lib/occi/core/errors/category_validation_error.rb
354
354
  - lib/occi/core/errors/collection_lookup_error.rb
355
355
  - lib/occi/core/errors/instance_validation_error.rb
356
+ - lib/occi/core/errors/location_validation_error.rb
356
357
  - lib/occi/core/errors/mandatory_argument_error.rb
357
358
  - lib/occi/core/errors/model_lookup_error.rb
358
359
  - lib/occi/core/errors/parser_error.rb
@@ -377,6 +378,7 @@ files:
377
378
  - lib/occi/core/instance_builder.rb
378
379
  - lib/occi/core/kind.rb
379
380
  - lib/occi/core/link.rb
381
+ - lib/occi/core/locations.rb
380
382
  - lib/occi/core/mixin.rb
381
383
  - lib/occi/core/model.rb
382
384
  - lib/occi/core/parsers.rb
@@ -415,6 +417,7 @@ files:
415
417
  - lib/occi/core/renderers/json/collection.rb
416
418
  - lib/occi/core/renderers/json/instance.rb
417
419
  - lib/occi/core/renderers/json/link.rb
420
+ - lib/occi/core/renderers/json/locations.rb
418
421
  - lib/occi/core/renderers/json/model.rb
419
422
  - lib/occi/core/renderers/json/resource.rb
420
423
  - lib/occi/core/renderers/json_renderer.rb
@@ -426,6 +429,7 @@ files:
426
429
  - lib/occi/core/renderers/text/collection.rb
427
430
  - lib/occi/core/renderers/text/instance.rb
428
431
  - lib/occi/core/renderers/text/link.rb
432
+ - lib/occi/core/renderers/text/locations.rb
429
433
  - lib/occi/core/renderers/text/model.rb
430
434
  - lib/occi/core/renderers/text/resource.rb
431
435
  - lib/occi/core/renderers/text_renderer.rb