Module: Foobara::Scoped

Included in:
CommandRegistry::ExposedCommand, Namespace::IsNamespace
Defined in:
foobara-0.7.3/projects/typesystem/projects/namespace/src/scoped.rb

Defined Under Namespace

Classes: NoScopedPathSetError

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#foobara_manifest_reference ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 89

def foobara_manifest_reference
  if scoped_unregistered?
    # TODO: can probably delete this defensive check
    # simplecov:disable
    raise "Cannot use unregistered Scoped object"
    # simplecov:enable
  end

  @foobara_manifest_reference ||= scoped_full_name
end

#scoped_namespace ⇒ Object

Returns the value of attribute scoped_namespace.



5
6
7
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 5

def scoped_namespace
  @scoped_namespace
end

#unregistered_foobara_manifest_reference ⇒ Object

Returns the value of attribute unregistered_foobara_manifest_reference.



6
7
8
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 6

def unregistered_foobara_manifest_reference
  @unregistered_foobara_manifest_reference
end

Instance Method Details

#scoped_absolute_name ⇒ Object



100
101
102
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 100

def scoped_absolute_name
  @scoped_absolute_name ||= "::#{scoped_full_name}"
end

#scoped_category ⇒ Object



125
126
127
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 125

def scoped_category
  @scoped_category ||= Namespace.global.foobara_category_symbol_for(self)
end

#scoped_clear_caches ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 30

def scoped_clear_caches
  [
    :@scoped_absolute_name,
    :@scoped_name,
    :@scoped_prefix,
    :@scoped_full_name,
    :@scoped_full_path,
    :@scoped_short_name,
    :@scoped_short_path
  ].each do |variable|
    remove_instance_variable(variable) if instance_variable_defined?(variable)
  end
end

#scoped_full_name ⇒ Object



83
84
85
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 83

def scoped_full_name
  @scoped_full_name ||= scoped_full_path.join("::")
end

#scoped_full_path ⇒ Object



79
80
81
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 79

def scoped_full_path
  @scoped_full_path ||= [*scoped_namespace&.scoped_full_path, *scoped_path]
end

#scoped_ignore_module?(mod) ⇒ Boolean

Returns:

  • (Boolean)


116
117
118
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 116

def scoped_ignore_module?(mod)
  @scoped_ignore_modules&.include?(mod) || scoped_namespace&.scoped_ignore_module?(mod)
end

#scoped_ignore_modules=(modules) ⇒ Object



120
121
122
123
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 120

def scoped_ignore_modules=(modules)
  mods = @scoped_ignore_modules || []
  @scoped_ignore_modules = [*mods, *modules]
end

#scoped_name ⇒ Object



71
72
73
74
75
76
77
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 71

def scoped_name
  return @scoped_name if defined?(@scoped_name)

  @scoped_name = unless scoped_path.empty?
                   scoped_path.join("::")
                 end
end

#scoped_name=(name) ⇒ Object



44
45
46
47
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 44

def scoped_name=(name)
  name = name.to_s if name.is_a?(::Symbol)
  self.scoped_path = name.split("::")
end

#scoped_path ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 8

def scoped_path
  if scoped_unregistered?
    # simplecov:disable
    raise "Cannot use unregistered Scoped object"
    # simplecov:enable
  end

  unless defined?(@scoped_path)
    # simplecov:disable
    raise NoScopedPathSetError, "No scoped path set. Explicitly set it to nil if that's what you want."
    # simplecov:enable
  end

  @scoped_path
end

#scoped_path=(path) ⇒ Object



49
50
51
52
53
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 49

def scoped_path=(path)
  scoped_clear_caches

  @scoped_path = path.map(&:to_s)
end

#scoped_path_autoset=(bool) ⇒ Object



55
56
57
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 55

def scoped_path_autoset=(bool)
  @scoped_path_autoset = bool
end

#scoped_path_autoset? ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 59

def scoped_path_autoset?
  @scoped_path_autoset
end

#scoped_path_set? ⇒ Boolean

Returns:

  • (Boolean)


112
113
114
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 112

def scoped_path_set?
  defined?(@scoped_path)
end

#scoped_prefix ⇒ Object



104
105
106
107
108
109
110
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 104

def scoped_prefix
  return @scoped_prefix if defined?(@scoped_prefix)

  @scoped_prefix = unless scoped_path.size == 1
                     scoped_path[0..-2]
                   end
end

#scoped_reregistering! ⇒ Object



137
138
139
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 137

def scoped_reregistering!
  @scoped_unregistered = nil
end

#scoped_short_name ⇒ Object



63
64
65
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 63

def scoped_short_name
  @scoped_short_name ||= scoped_path[-1]
end

#scoped_short_path ⇒ Object



67
68
69
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 67

def scoped_short_path
  @scoped_short_path ||= [scoped_short_name]
end

#scoped_unregistered! ⇒ Object



129
130
131
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 129

def scoped_unregistered!
  @scoped_unregistered = true
end

#scoped_unregistered? ⇒ Boolean

Returns:

  • (Boolean)


133
134
135
# File 'projects/typesystem/projects/namespace/src/scoped.rb', line 133

def scoped_unregistered?
  @scoped_unregistered
end