Class: Occi::Core::Locations

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Helpers::ArgumentValidator, Helpers::Renderable, Yell::Loggable
Defined in:
lib/occi/core/locations.rb

Overview

Implments handling helpers for OCCI locations. These are especially useful for rendering and butter-passing purposes.

Author:

Constant Summary collapse

ENUM_METHODS =

Methods to be redirected to `uris`

%i[each << add remove map! empty? include?].freeze

Constants included from Helpers::Renderable

Helpers::Renderable::RENDERER_FACTORY_CLASS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Renderable

extended, included, #render, #renderer_factory, renderer_factory, renderer_factory_class, #renderer_for

Constructor Details

#initialize(args = {}) ⇒ Locations

Constructs an instance with given URIs. If `uris` are omitted, an empty set will be automatically provided.

Options Hash (args):

  • :uris (Set)

    collection of URIs representing locations


26
27
28
29
30
31
32
33
# File 'lib/occi/core/locations.rb', line 26

def initialize(args = {})
  pre_initialize(args)
  default_args! args

  @uris = args.fetch(:uris)

  post_initialize(args)
end

Instance Attribute Details

#urisSet

collection of URIs representing locations


9
10
11
# File 'lib/occi/core/locations.rb', line 9

def uris
  @uris
end

Instance Method Details

#host=(host) ⇒ Object

Applies given `host` to all locations contained in the collection.


38
39
40
# File 'lib/occi/core/locations.rb', line 38

def host=(host)
  each { |uri| uri.host = host }
end

#port=(port) ⇒ Object

Applies given `port` to all locations contained in the collection.


45
46
47
# File 'lib/occi/core/locations.rb', line 45

def port=(port)
  each { |uri| uri.port = port }
end

#scheme=(scheme) ⇒ Object

Applies given `scheme` to all locations contained in the collection.


52
53
54
# File 'lib/occi/core/locations.rb', line 52

def scheme=(scheme)
  each { |uri| uri.scheme = scheme }
end

#valid!Object Also known as: convert!

Validates all locations in the collections and raises an error if there is an invalid location. During this process, all locations will be converted to `URI` instances.

Raises:


74
75
76
77
78
# File 'lib/occi/core/locations.rb', line 74

def valid!
  map! { |uri| return_or_convert uri }
rescue => ex
  raise Occi::Core::Errors::LocationValidationError, ex.message
end

#valid?TrueClass, FalseClass

Validates all locations contained in the collection. Validation errors are only logged.


61
62
63
64
65
66
67
# File 'lib/occi/core/locations.rb', line 61

def valid?
  valid!
  true
rescue => ex
  logger.warn "Location invalid: #{ex.message}"
  false
end