Module: Foobara::Domain

Defined in:
foobara-0.5.8/projects/typesystem/projects/domain/src/domain.rb,
foobara-0.5.8/projects/typesystem/projects/domain/lib/foobara/domain.rb,
foobara-0.5.8/projects/typesystem/projects/domain/src/module_extension.rb,
foobara-0.5.8/projects/command/src/extensions/domain/domain_module_extension.rb,
foobara-0.5.8/projects/typesystem/projects/domain/src/domain_module_extension.rb,
foobara-0.5.8/projects/typesystem/projects/domain/src/organization_module_extension.rb,
foobara-0.5.8/projects/entities/projects/entity/src/extensions/domain/domain_module_extension.rb

Defined Under Namespace

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

Class Method Summary collapse

Class Method Details

.copy_constants(old_mod, new_class) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'projects/typesystem/projects/domain/src/domain.rb', line 81

def copy_constants(old_mod, new_class)
  old_mod.constants.each do |const_name|
    value = old_mod.const_get(const_name)
    if new_class.const_defined?(const_name)
      to_replace = new_class.const_get(const_name)
      if to_replace != value
        new_class.send(:remove_const, const_name)
        new_class.const_set(const_name, value)
      end
    else
      new_class.const_set(const_name, value)
    end
  end
end

.create(full_domain_name) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'projects/typesystem/projects/domain/src/domain.rb', line 56

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



77
78
79
# File 'projects/typesystem/projects/domain/src/domain.rb', line 77

def current
  to_domain(Namespace.current)
end

.domain_through_modules(mod) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'projects/typesystem/projects/domain/src/domain.rb', line 37

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



71
72
73
74
75
# File 'projects/typesystem/projects/domain/src/domain.rb', line 71

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 'projects/typesystem/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 'projects/typesystem/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
# File 'projects/typesystem/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
    elsif object == Namespace.global
      GlobalDomain
    elsif object.scoped_path_set? && object.scoped_path.empty?
      object.foobara_lookup_domain!("")
    else
      to_domain(object.scoped_namespace)
    end
  else
    # :nocov:
    raise NoSuchDomain, "Couldn't determine domain for #{object}"
    # :nocov:
  end
end