Class: Entitlements::Util::Mirror

Inherits:
Object
  • Object
show all
Includes:
Contracts::Core
Defined in:
lib/entitlements/util/mirror.rb

Constant Summary collapse

C =
::Contracts

Class Method Summary collapse

Methods included from Contracts::Core

common, extended, included

Class Method Details

.validate_mirror!(key) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/entitlements/util/mirror.rb', line 16

def self.validate_mirror!(key)
  # Make sure there is not an existing file, directory, or anything else in the
  # directory structure defined by this key.
  begin
    src = Entitlements::Util::Util.path_for_group(key)
    raise ArgumentError, "#{key.inspect} is declared as a mirror OU but source #{src.inspect} exists!"
  rescue Errno::ENOENT
    # This is desired.
  end

  # Make sure the target exists.
  target = Entitlements.config["groups"][key]["mirror"]
  unless Entitlements.config["groups"].key?(target)
    raise ArgumentError, "#{key.inspect} is declared as a mirror to a non-existing target #{target.inspect}!"
  end

  # Make sure the target is not itself a mirror.
  if Entitlements.config["groups"][target]["mirror"]
    raise ArgumentError, "#{key.inspect} is declared as a mirror to a mirror target #{target.inspect}!"
  end

  # All is well
  nil
end