class Occi::Core::Locations

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

@attr uris [Set] collection of URIs representing locations

@author Boris Parak <parak@cesnet.cz>

Constants

ENUM_METHODS

Methods to be redirected to `uris`

Attributes

uris[RW]

Public Class Methods

new(args = {}) click to toggle source

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

@param args [Hash] arguments with Location information @option args [Set] :uris collection of URIs representing locations

# 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

Public Instance Methods

convert!()
Alias for: valid!
host=(host) click to toggle source

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

@param host [String] hostname for locations

# File lib/occi/core/locations.rb, line 38
def host=(host)
  each { |uri| uri.host = host }
end
port=(port) click to toggle source

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

@param port [String] port number

# File lib/occi/core/locations.rb, line 45
def port=(port)
  each { |uri| uri.port = port }
end
scheme=(scheme) click to toggle source

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

@param scheme [String] URI scheme

# File lib/occi/core/locations.rb, line 52
def scheme=(scheme)
  each { |uri| uri.scheme = scheme }
end
valid!() click to toggle source

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.

@raise [Occi::Core::Errors::LocationValidationError] if some location is invalid

# 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
Also aliased as: convert!
valid?() click to toggle source

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

@return [TrueClass] if locations are valid @return [FalseClass] if locations are invalid

# File lib/occi/core/locations.rb, line 61
def valid?
  valid!
  true
rescue => ex
  logger.warn "Location invalid: #{ex.message}"
  false
end