Module: Foobara::Domain

Defined in:
foobara-0.0.110/projects/domain/src/domain.rb,
foobara-0.0.110/projects/domain/lib/foobara/domain.rb,
foobara-0.0.110/projects/domain/src/module_extension.rb,
foobara-0.0.110/projects/domain/src/domain_module_extension.rb,
foobara-0.0.110/projects/domain/src/organization_module_extension.rb

Defined Under Namespace

Modules: DomainModuleExtension, ModuleExtension, OrganizationModuleExtension Classes: AlreadyRegisteredError, CannotSetTypeConstantError, DomainAlreadyExistsError, NoSuchDomain

Class Method Summary collapse

Class Method Details

.create(full_domain_name) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'foobara-0.0.110/projects/domain/src/domain.rb', line 58

def create(full_domain_name)
  if Domain.to_domain(full_domain_name)
    raise DomainAlreadyExistsError, "Domain #{full_domain_name} already exists"
  end
rescue Domain::NoSuchDomain
  begin
    Util.make_module(full_domain_name) { foobara_domain! }
  rescue Util::ParentModuleDoesNotExistError => e
    # TODO: this doesn't feel like the right logic... how do we know this isn't a prefix instead of an
    # organization?
    Util.make_module(e.parent_name) { foobara_organization! }
    Util.make_module(full_domain_name) { foobara_domain! }
  end
end

.currentObject



79
80
81
# File 'foobara-0.0.110/projects/domain/src/domain.rb', line 79

def current
  to_domain(Namespace.current)
end

.domain_through_modules(mod) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'foobara-0.0.110/projects/domain/src/domain.rb', line 39

def domain_through_modules(mod)
  mod = Util.module_for(mod)

  while mod
    if mod.foobara_domain?
      namespace = mod
      break
    end

    mod = Util.module_for(mod)
  end

  if namespace&.foobara_domain?
    namespace
  else
    GlobalDomain
  end
end

.foobara_type_from_declaration(scoped, type_declaration) ⇒ Object



73
74
75
76
77
# File 'foobara-0.0.110/projects/domain/src/domain.rb', line 73

def foobara_type_from_declaration(scoped, type_declaration)
  domain = to_domain(scoped)

  domain.foobara_type_from_declaration(type_declaration)
end

.globalObject



8
9
10
# File 'foobara-0.0.110/projects/domain/src/domain_module_extension.rb', line 8

def global
  GlobalDomain
end

.install!Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'foobara-0.0.110/projects/domain/lib/foobara/domain.rb', line 4

def install!
  if @installed
    # :nocov:
    raise "Already registered Domain"
    # :nocov:
  end

  # TODO: delete this?
  @installed = true

  Namespace.global.foobara_add_category(:organization) { is_a?(Module) && foobara_organization? }
  Namespace.global.foobara_add_category(:domain) { is_a?(Module) && foobara_domain? }
end

.to_domain(object) ⇒ Object



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
32
33
34
35
36
37
# File 'foobara-0.0.110/projects/domain/src/domain.rb', line 6

def to_domain(object)
  case object
  when nil
    global
  when ::String, ::Symbol
    domain = Namespace.global.foobara_lookup_domain(object)

    unless domain
      # :nocov:
      raise NoSuchDomain, "Couldn't determine domain for #{object}"
      # :nocov:
    end

    domain
  when Foobara::Scoped
    if object.is_a?(Module) && object.foobara_domain?
      object
    else
      parent = object.scoped_namespace

      if parent
        to_domain(parent)
      else
        GlobalDomain
      end
    end
  else
    # :nocov:
    raise NoSuchDomain, "Couldn't determine domain for #{object}"
    # :nocov:
  end
end